sql

Difference between FETCH/FOR to loop a CURSOR in PL/SQL

I know that fetching a cursor will give me access to variables like %ROWCOUNT, %ROWTYPE, %FOUND, %NOTFOUND, %ISOPEN ...but I was wondering if there are any other reasons to use Open - Fetch - Close instructions to loop a cursor rather than Loop the cursor with a FOR cycle... (In my opinion this is better becase it is simple) What...

Importing/Pasting Excel data with changing fields into SQL table

I have a table called Animals. I pull data from this table to populate another system. I get Excel data with lists of animals that need to go in the Animals table. The Excel data will also have other identifiers, like Breed, Color, Age, Favorite Toy, Veterinarian, etc. These identifiers will change with each new excel file. Some may...

How can I explore the data in a SQL database, including foreign tables?

I want to know if any tools exist to explore the data in a relational database, and to drill through master-detail relationships. I already know how to view the data in a single table, and I know how to construct SQL queries that JOIN tables. However, to get N-levels deep, I have to write a SQL statement, find the ID of the item I'm in...

Can I use trim in a sql query condition

Hi I am creating a reverse phone number look up in my database. I have a box that the user enters a phone number (in my example the number is 01772708200 NO SPACES etc) What I want to do is query my sql database and return matching results. The problem is my database contains thousands of numbers in different formats (I should have forma...

How to change this SQL so that I can get one post from each author?

In the sql below I have the last 5 posts. But sometimes these posts are from the same author. I want to select the last 5 but just one per author. SELECT `e` . * , `f`.`title` AS `feedTitle` , `f`.`url` AS `feedUrl` , `a`.`id` AS `authorId` , `a`.`name` AS `authorName` , `a`.`about` AS `authorAbou...

Data provider class for sql database

I need to write a data provider class to pull data from a sql database for use in a webpage that will display a bing map. Does anyone have a link they could provide with a tutorial on how to do this? I have very little experience using a db to provide dynamic data for a web page so any help is appreciated. The Database is a sql Azur...

Why does my SQL query of date fields sometimes need trunc() (Oracle)?

I have two tables where I was querying on a date column in each table. In one case need to use the trunc() function on the date field to get values back, on the other I do not. That is this works on table 1: SELECT to_char( datecol1 ,'mm/dd/yyyy hh:mm:ss') FROM table1 where datecol1 =to_date('10/07/2010', 'mm/dd/yyyy'); But o...

SQL Select Return Default Value If Null

Database: MS SQL 2008 SELECT Listing.Title, Listing.MLS, Pictures.PictureTH, Pictures.Picture, Listing.ID FROM Listing INNER JOIN Pictures ON Listing.ID = Pictures.ListingID WHERE (Pictures.ID = (SELECT MIN(ID) FROM Pictures WHERE (ListingID = Listing.ID))) The issue is, I have several "Listings" without a Picture, and because of thi...

Does SQL Server 2008 Service Pack 2 Apply to SQL Server 2008 R2?

I've been using SQL Server 2008 R2 for my development. I noticed that service pack 2 for SQL Server 2008 just came out. However, I checked here and Microsoft does not provide a link to any of the service packs for SQL Server 2008 R2. So it is not clear to me whether or not I should apply their service pack to my instance of SQL Server 20...

SQL server 2005 - compact edition and express edition

I have a database program developed in Visual Studios 2005. It uses SQL Express in creating and connecting to the database. I have created a deployment package with SQL Express. Can this be installed on a PC that has SQL 2005 Compact Edition installed? ...

Efficient database searching for LIKE '%something%'

I'm trying to search through phone numbers for any phone number containing some series of digits. Obviously the following is going to be slow: Select * from customer where phone like '%1234%' I need the wildcards, because the users were allowed to enter any data in the database, so it might have country codes, a leading 1 (as in 1...

Walking a tree backwards in SQL

Hello: I have a table with a very simple schema: CREATE TABLE q( orig INTEGER NOT NULL, dest INTEGER NOT NULL, cost FLOAT, PRIMARY KEY (orig, dest) ); I need to walk that table backwards in a cost minimizing way. Let me explain. I need a tour of 15 points, a point can be an orig or a dest. My algorithm is a backtracking from t...

Table Recovery Question

Suppose that I have a table with the following schema: tableId field1 field2 ..... I have two copies of my database (backup and production). On the production instance, a query was accidentally run which did the following: Update table set field2 = null where field1 = 'x'; I am trying to undo this query based on the data stored ...

SQL JOIN question (yet another one)

Sounds simple but I'm stuck Table A Table B col_a col_b col_a col_c 1 b 1 c 2 c 2 d 3 z 3 a 4 d 4 e 33 a 5 k 6 l 33 b 33 ...

SQL GROUP BY CLAUSE

I have a table where I'm trying to pull some trend analysis from where the columns are Date(timestamp),RiskCategory(text) and Point(int). What I'm trying to return is for every date SUM the points and group by RiskCategory. I can get the latest via the following: SELECT Date,RiskCategory,SUM(Point) AS Total FROM risktrend WHERE DATE(Da...

SQL - Insert query Inside another Insert with updated Identity seed

I have 2 tables T1 AND T2 T1 has 10 unique records with a primary key (Identity Seed) T2 has multiple entires with Foreign Key for each record in T1 T1 has 2 columns : PrimaryKey - DATA T2 has 2 columns : PrimaryKey - FoeignKey (this FK is the Primary Key of T1) I need to write a query which will select all the records from T1 and INS...

MySQL's now() +1 day

I'm using now() in MySQL query. INSERT INTO table SET data = '$data', date = now() But I want to add 1 day to this date (so that date should contain tomorrow). Is it possible? ...

Adding minutes to datetime on insert - mysql

I've tried this INSERT INTO products (product_id, product_type, created_dt, end_dt) VALUES ('11', '1', '2010-10-08 00:11:10', DATE_SUB(2010-10-08 00:11:10, INTERVAL 59 Minute)) But this doesn't work. Any other ways to do this within Mysql? Thanks! ...

Alternative strategy to query aggregation ("group by") in google app engine datastore

App Engine Datastore cannot be queried for an aggregate result. Example: I have an entity called "Post" with the following fields: Key id, String nickname, String postText, int score I have many different nicknames and many posts by each nickname in my datastore. If I want a leader board of the top ten nicknames of total scores, I w...

Global temporary tables in SQL Server

I have a ##table which can be accessed across all the sessions but sometimes I am getting error There is already an object named '##table' in the database. WHY and how to resolve it. ...