?
Solved

Need help with CASE statement

Posted on 2010-01-06
4
Medium Priority
?
260 Views
Last Modified: 2012-05-08
I have read CASE syntax, but I am still confuse.  I want to write a CASE base on targetID as follow:

targetID = 1
FabricToSend="1 yard"

targetID = 2
FabricToSend = "2 yard"

i have no clue on how to start. :(  
can someone guide me?

thanks
0
Comment
Question by:aspnewbie09
4 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 375 total points
ID: 26191784
SELECT FabricToSend = CASE (TargetID) when 1 then '1 yard' when 2 then '2 Yard' else null end


or


SELECT  FabricToSend =  = CAST (TargetID as varchar)+ ' yard'
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 26191847
The latter needs to be
SELECT  FabricToSend = CAST (TargetID as varchar)+ ' yard'
of course (single equal sign).
And CASE works without those parens, they are not needed.
0
 
LVL 26

Expert Comment

by:tigin44
ID: 26191868
SELECT CASE WHEN targetID = 1 THEN '1 yard'
                  WHEN targetID = 2 THEN '2 yard'
                  ELSE ''
            END AS FabricToSend
0
 

Author Closing Comment

by:aspnewbie09
ID: 31673548
instruction not accurate.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question