Solved

Case stmt

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

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 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

13 Experts available now in Live!

Get 1:1 Help Now