468,310 Members | 1,418 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,310 developers. It's quick & easy.

DECODE in SQL Server?"

N
What is the function in SQL that works like DECODE in Oracle?"

Thanks,

N

Jul 20 '05 #1
10 110235
Use CASE

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
N
SELECT CASE WHEN Assignment_Type = 'C' THEN 'Com' ELSE 'Donot Know'
FROM ASSIGNMENT

When I try to use CASE WHEN, it gave me error [Microsoft][ODBC SQL Server
Driver][SQL Server]Incorrect syntax near the keyword 'FROM'. What did I do
wrong?

Thanks

"David Portas" <RE****************************@acm.org> wrote in message
news:24********************@giganews.com...
Use CASE

--
David Portas
SQL Server MVP
--

Jul 20 '05 #3
> What did I do
wrong?


You didn't read-up on the syntax first! My reply was intended as an
indication of something you should look up. You'll find Books Online is a
great resource if you refer to it occassionally :-)

SELECT CASE WHEN Assignment_Type = 'C' THEN 'Com' ELSE 'Do not know' END
FROM ASSIGNMENT

or

SELECT CASE Assignment_Type WHEN 'C' THEN 'Com' ELSE 'Do not know' END
FROM ASSIGNMENT

--
David Portas
SQL Server MVP
--
Jul 20 '05 #4
N
David,

Sorry, I don't have books online. The examples I found on the site, none of
them used "END" in the statment.

Thanks a bunch! ^_____^
N
"David Portas" <RE****************************@acm.org> wrote in message
news:5M********************@giganews.com...
What did I do
wrong?


You didn't read-up on the syntax first! My reply was intended as an
indication of something you should look up. You'll find Books Online is a
great resource if you refer to it occassionally :-)

SELECT CASE WHEN Assignment_Type = 'C' THEN 'Com' ELSE 'Do not know' END
FROM ASSIGNMENT

or

SELECT CASE Assignment_Type WHEN 'C' THEN 'Com' ELSE 'Do not know' END
FROM ASSIGNMENT

--
David Portas
SQL Server MVP
--

Jul 20 '05 #5
Get BOL here:
http://www.microsoft.com/sql/techinf...00/default.asp

--
David Portas
SQL Server MVP
--
Jul 20 '05 #6
N wrote:
What is the function in SQL that works like DECODE in Oracle?"

Thanks,

N


As you know CASE is not the same as DECODE ... but SQL Server hsa no
functionality equivalent to DECODE so you will have to adapt CASE to
do the job.
--
Daniel A. Morgan
University of Washington
da******@x.washington.edu
(replace 'x' with 'u' to respond)

Jul 20 '05 #7
Daniel Morgan wrote:
N wrote:
What is the function in SQL that works like DECODE in Oracle?"

Thanks,

N

As you know CASE is not the same as DECODE ... but SQL Server hsa no
functionality equivalent to DECODE so you will have to adapt CASE to
do the job.

How is DECODE different than "simple CASE"?
(Other than that DECODE is a function and CASE an expression, of course...)

Cheers
Serge
Jul 20 '05 #8
You can also find the books online online at

http://msdn.microsoft.com/library/de...server2000.asp

Open up the SDK Documentation tree item.

Muhd

"David Portas" <RE****************************@acm.org> wrote in message
news:5a********************@giganews.com...
Get BOL here:
http://www.microsoft.com/sql/techinf...00/default.asp

--
David Portas
SQL Server MVP
--

Jul 20 '05 #9
"Daniel Morgan" <da******@x.washington.edu> wrote in message
news:1096932539.547042@yasure...
N wrote:
What is the function in SQL that works like DECODE in Oracle?"
Thanks,

N


As you know CASE is not the same as DECODE ... but SQL Server hsa no
functionality equivalent to DECODE so you will have to adapt CASE to
do the job.
--
Daniel A. Morgan
University of Washington
da******@x.washington.edu
(replace 'x' with 'u' to respond)


OK, then, what does DECODE do?
Jul 20 '05 #10
-P-
"DHatheway" <dl********@mmm.com.nospam> wrote in message news:ck**********@tuvok3.mmm.com...
"Daniel Morgan" <da******@x.washington.edu> wrote in message
news:1096932539.547042@yasure...
N wrote:
What is the function in SQL that works like DECODE in Oracle?"
Thanks,

N


As you know CASE is not the same as DECODE ... but SQL Server hsa no
functionality equivalent to DECODE so you will have to adapt CASE to
do the job.
--
Daniel A. Morgan
University of Washington
da******@x.washington.edu
(replace 'x' with 'u' to respond)


OK, then, what does DECODE do?

DECODE( exp, search1, result1 [,search2, result2]... ) is semantically equivalent to:

CASE exp
when search1 then result1
when search2 then result2
... END

The difference between CASE and DECODE is that CASE also allows the form:
CASE
WHEN exp1 = search1 then result1
WHEN exp2 = search2 then result2
... END

DECODE can't do that.

--
Paul Horan[TeamSybase]

VCI Springfield, Mass
www.vcisolutions.com

Jul 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jim Moon | last post: by
2 posts views Thread by Jim Moon | last post: by
1 post views Thread by SibAndela | last post: by
3 posts views Thread by Jim in Arizona | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.