Solved

sql query

Posted on 2011-09-26
3
283 Views
Last Modified: 2012-05-12
Using MS Sql Server 2008.

My table has field name  DCode1, DCode2, DCode3, DCode4, DCode5. The values of all these DCode fields is either 'F1' or 'F7'.
I want to write a select statement with the following constraint:
When any DCode value is F1 then Go in F1, if DCode value is 'F7', then go in F7.

Select ???? as F1, ???? as F7.............How do I do that?

Thanks.
0
Comment
Question by:patd1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Expert Comment

by:tim_cs
ID: 36599615
I'm not really sure what you're talking about when you say go in F1/F7.  Can you provide some example data including what it looks like in the table and what the expected results are?
0
 

Author Comment

by:patd1
ID: 36599659
example:
DCode1, Dcode2,Dcode3, Dcode4, Dcode5
F1, F7, a,b,c
a,b,F1,d,e
F7,a,b,c,d

I want this to display as follows:
F1, F7
Y,Y
Y,N
N,Y

Thanks.
0
 
LVL 5

Accepted Solution

by:
bitref earned 500 total points
ID: 36600454
Select (Case When (DCode1 = 'F1' OR DCode2 = 'F1' OR DCode3 = 'F1' OR DCode4 = 'F1' OR DCode5 = 'F1') Then 'Y' Else 'N' END) as F1
, (Case When (DCode1 = 'F7' OR DCode2 = 'F7' OR DCode3 = 'F7' OR DCode4 = 'F7' OR DCode5 = 'F7') Then 'Y' Else 'N' END) as F7
From MyTable

Open in new window

0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

689 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