Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Does MS SQL have an equivalent function...?

Author  Topic 

michael.conner10@gte.net
Starting Member

2 Posts

Posted - 2006-11-16 : 14:04:45
...For Oracles DECODE function?

I am trying to get a conditional output RETURNed to the Grid output and have not found it in SQL Help. Help!!!

Here is Oracles example:

Select Distinct City,
DECODE (City, 'Cincinnati', 'Queen City', 'New York', 'Big Apple', 'Chicago',
'City of Broad Shoulders', City) AS Nickname
From Cities;


Kristen
Test

22859 Posts

Posted - 2006-11-16 : 14:09:08
[code]
Select Distinct City, Nickname
From Cities AS C
JOIN
(
SELECT [City] = 'Cincinnati', [Nickname] = 'Queen City'
UNION ALL 'New York', 'Big Apple'
UNION ALL SELECT 'Chicago', 'City of Broad Shoulders'
) AS D
ON C.City = D.City
[/code]
but I would want these sort of lookups in a table of their own in the first place, and provide the End User with a maintenance tool so they can add new ones.

You could also use a CASE statement in the SELECT clause:
[code]
Select Distinct City,
[Nickname] = CASE City
WHEN 'Cincinnati' THEN 'Queen City'
WHEN 'New York' THEN 'Big Apple'
....
END
[/code]
Kristen
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-11-16 : 14:09:16
no it doesn't.
you'll have to play with case expression.



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-11-16 : 14:21:24
wow, 5 minute anser and then 8 seconds apart



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

michael.conner10@gte.net
Starting Member

2 Posts

Posted - 2006-11-16 : 15:25:55
Thanks so much Kristen and Spirit1. I truly appreciate your assistance.



Cordially,

C. Michael Conner, PMP
michael.conner10@gte.net
425.489.9014 (home)
425.260.3838 (pcs)
Go to Top of Page
   

- Advertisement -