Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy Case Statement

Status
Not open for further replies.

TechieTony

IS-IT--Management
Mar 21, 2008
42
US
I am not a sql guy buy any means but I have to write alittle code at times. I need to write a case statement that does the following.

If my P21PLAY.dbo.p21_view_oe_pick_ticket.carrier_id is equal to (105999, 566588)

THEN S

If my P21PLAY.dbo.p21_view_oe_pick_ticket.carrier_id is equal to (105997, 566545)

THEN R

If my P21PLAY.dbo.p21_view_oe_pick_ticket.carrier_id is equal to (105992, 566509)

THEN T AS BILL_TO

------------------------------------------------
I tried using this case (left out all the values)

CASE P21PLAY.dbo.p21_view_oe_pick_ticket.carrier_id

WHEN 105993, 105225 THEN 'S'
WHEN 999999 THEN 'R'
WHEN 888888 THEN 'T'
ELSE 'OTHER' END AS Bill_To


But still doesnt fly.... am I missing something here?? any help is appreciated

Noncentz







 
I managed to get This to work....

CASE P21PLAY.dbo.p21_view_oe_pick_ticket.carrier_id

WHEN 105993 THEN 'S'
WHEN 999999 THEN 'R'
WHEN 888888 THEN 'T'
ELSE 'OTHER' END AS Bill_To

The problem is I cant seem to be able to use multiple values such as

WHEN (105993, 777777,666666) THEN 'S'
WHEN 999999 THEN 'R'
WHEN 888888 THEN 'T'
ELSE 'OTHER' END AS Bill_To

I keep getting an error?
 
try this format
Code:
case when myfield in (1,2,3) then x
else y
end
[code]


"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top