Solved

Case stmt

Posted on 2008-10-24
5
232 Views
Last Modified: 2012-05-05
I have 2 diff fields, code which is always "1M" and inv_cd which is 001 and 002...in my following case stmt i would to say that if code is 1M then 'FM' but if inv_cd has 002 then SOLDMTG, in following stmt i am getting all FM even in some inv_cd there is 002, is this possible?


case when code = '1M' then 'FM' when inv_cd = 002 then 'SOLDMTG' end as PRODID
0
Comment
Question by:fahVB
  • 3
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22796213
002 is char?

case when code = '1M' then 'FM' when inv_cd = '002' then 'SOLDMTG' end as PRODID

Open in new window

0
 

Author Comment

by:fahVB
ID: 22796239
I tried with commas but still get all FM
0
 

Author Comment

by:fahVB
ID: 22796271
and yes it is char(3)
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22796316
well, the order of the WHEN clauses is important:
case when inv_cd = '002' then 'SOLDMTG' when code = '1M' then 'FM'  end as PRODID

Open in new window

0
 

Author Closing Comment

by:fahVB
ID: 31509651
i didn't know that, thank you ...it worked
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to enforce inte 8 59
Error when saving to sql table a '/' 5 30
Query to return total 6 22
Why i am getting a star, SSMS does not show me any error. Division Error 5 33
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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