If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Equivalent of Oracle's DECODE function on SQLServer

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-04-02, 14:58
jofph jofph is offline
Registered User
 
Join Date: Mar 2002
Posts: 4
Equivalent of Oracle's DECODE function on SQLServer

What is the equivalent function in SQL server for the DECODE function in Oracle?

For example:
select decode(customer_type,'B','Business','Non Business')
from CUSTOMER_TABLE

This is the function statement that we use currently in Oracle. I need to do this same function in Sql server.

Thanks for all help.
Reply With Quote
  #2 (permalink)  
Old 03-04-02, 15:29
achorozy achorozy is offline
Here to Help
 
Join Date: Dec 2001
Location: Toronto, Canada
Posts: 335
I'm assuming that customer_type may or may not contain the character 'B'.

For SQL Server

Code:
SELECT CASE customer_type
                 WHEN 'B' THEN 'Business'
                  ELSE 'Non Business'
            END
FROM CUSTOMER_TABLE 

OR

SELECT CASE WHEN customer_type = 'B' THEN 'Business'
                  ELSE 'Non Business'
            END
FROM CUSTOMER_TABLE
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On