Thanks,
NUse CASE
--
David Portas
SQL Server MVP
--|||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" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:24GdncWmqJeLKfzcRVn-vg@.giganews.com...
> Use CASE
> --
> David Portas
> SQL Server MVP
> --|||> 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
--|||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" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:5MGdne_kiKNeKvzcRVn-gw@.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
> --|||Get BOL here:
http://www.microsoft.com/sql/techin...000/default.asp
--
David Portas
SQL Server MVP
--|||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
damorgan@.x.washington.edu
(replace 'x' with 'u' to respond)|||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|||You can also find the books online online at
http://msdn.microsoft.com/library/d...lserver2000.asp
Open up the SDK Documentation tree item.
Muhd
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:5aOdncEAVOgnX_zcRVn-tA@.giganews.com...
> Get BOL here:
> http://www.microsoft.com/sql/techin...000/default.asp
> --
> David Portas
> SQL Server MVP
> --|||"Daniel Morgan" <damorgan@.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
> damorgan@.x.washington.edu
> (replace 'x' with 'u' to respond)
OK, then, what does DECODE do?|||"DHatheway" <dlhatheway@.mmm.com.nospam> wrote in message news:ck18oi$m31$1@.tuvok3.mmm.com...
> "Daniel Morgan" <damorgan@.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
> > damorgan@.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
No comments:
Post a Comment