473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DECODE in SQL Server?"

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

Thanks,

N

Jul 20 '05 #1
10 111232
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bonnie.tangyn | last post by:
Hello all I get Too few parameters expected 2 error and "The MS Jet Database engine cannot find the input table or query "myTempTablename". Make sure it exists and that its name is spelled...
0
by: Oliver | last post by:
> I am seeing an 'Access Denied' exception when using a "Server" "Serviced Component" >> ..are...registered in the GAC ? yes. >> ..are...the parameters serializable? um - parameters? - the...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
0
by: Jim Moon | last post by:
Hello. We have SQL Server Stored Procedures that use the "CURRENT_USER" variable. We have SQL Server database fields that call "user_name()" as a default. That has been fine in the use and...
2
by: Jim Moon | last post by:
Hello. We have SQL Server Stored Procedures that use the "CURRENT_USER" variable. We have SQL Server database fields that call "user_name()" as a default. That has been fine in the use and...
1
by: SibAndela | last post by:
Is there a way that I can attach the uploaded file from a client web site to the web server without first storing the uploaded file on the server? Currently on my local PC (local host) the...
3
by: Jim in Arizona | last post by:
Most of the asp.net learning I've done has been from books that were written during the 1.0 framework. I didn't have a copy of visual studio when I started reading them then I got a hold of VS 2005...
0
by: martin leer | last post by:
Hi all. I got the following error: OLE DB provider "MSDAORA" for linked server "infonet" returned message "Oracle client and networking components were not found. These components are...
3
by: Gilles Ganault | last post by:
Hello I'm getting this error while downloading and parsing web pages: ===== title = m.group(1) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 48: ordinal not in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.