Solved

sql query

Posted on 2011-09-26
3
233 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
3 Comments
 
LVL 15

Expert Comment

by:tim_cs
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

6 Experts available now in Live!

Get 1:1 Help Now