?
Solved

sql query

Posted on 2011-09-26
3
Medium Priority
?
290 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 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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 …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

765 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