View Single Post
Old 22-Oct-2007, 12:32 AM   #1 (permalink)
Anilrgowda
Administrator
 
Anilrgowda's Avatar

Posts: 18,715
Join Date: Jan 2006
Rep Power: 10 Anilrgowda is on a distinguished road

IM:
Default SQL Query when inserting data from one database to another.

Good afternoon,
I have a databases and I'm trying to get a portion of one table to a table in another database and when I run the following query it does transfer over the information and insert it into the second database, however what I'm trying to achieve for aesthetic reasons is to get the database to sort in the correct order before going into the new database. For the most part it's working except for I have a case statement to deal with the NULL values to change them to an actual value however as you can see from the output it's sorting mostly correct but putting the replacement for the NULL at the top instead of alphabetically where it should go. I'm including the scripts and output below and using the real names for the databases etc.

Script I use to transfer:

INSERT INTO DataSocial_DW.dbo.DimReason(ReasonNameTemp,ReasonName)
SELECT Distinct Reason,
CASE
WHEN Reason IS NULL THEN 'Not Supplied'
ELSE Reason
END
FROM [SalesForce].[dbo].[Case]
ORDER BY Reason

That returns the following output:

ReasonNameTemp ReasonName
1 NULL Not Supplied
2 Accessing PC Remotely Accessing PC Remotely
3 Instructions Not Clear Instructions Not Clear
4 Other Other
5 Product Issue Product Issue
6 User Error User Error
7 User Infrastructure Error User Infrastructure Error

I'd like to get the NULL sorted so that in the ReasonName column Not Supplied is sorted where it should be in field 3.

Any help would be appreciated, thanks!


------------------


Anilrgowda is offline   Reply With Quote