Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


sql query

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

Question by:patd1
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
LVL 15

Expert Comment

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?

Author Comment

ID: 36599659
DCode1, Dcode2,Dcode3, Dcode4, Dcode5
F1, F7, a,b,c

I want this to display as follows:
F1, F7


Accepted Solution

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


Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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