Solved

Case stmt

Posted on 2008-10-24
5
229 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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
I tried with commas but still get all FM
0
 

Author Comment

by:fahVB
Comment Utility
and yes it is char(3)
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
Comment Utility
i didn't know that, thank you ...it worked
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now