[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

TSQL multiple select statement

Posted on 2013-01-17
7
Medium Priority
?
484 Views
Last Modified: 2013-01-17
Hi have a multiple select statement as follows:
SELECT

TABLE.COL1            AS [EXT_LA],

TABLE.COL2             AS [EXT_LAO],
 
TABLE.COL3            AS[EXT_LA#]

I need to only pull 'abc' from col2 and 'def', and 'hijk' from col3 how would i go about doing that?

Thanks
0
Comment
Question by:Tech315
7 Comments
 
LVL 40

Expert Comment

by:lcohan
ID: 38789069
SELECT

TABLE.COL1            AS [EXT_LA],

TABLE.COL2             AS [EXT_LAO],
 
TABLE.COL3            AS[EXT_LA#]

WHERE TABLE.COL2 = 'def' AND (TABLE.COL3 = 'def' OR TABLE.COL3 = 'hijk' )
0
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 38789074
Can you provide some more information please for example when you say you only need to pull 'abc' from col2, do you mean the value should always be 'abc' or you only want to display the value when col2 = 'abc' or what? Please provide an example with real data.
0
 
LVL 8

Expert Comment

by:H
ID: 38789100
where
TABLE.COL2 = 'abc' and TABLE.COL3 = 'def'
or
TABLE.COL2 = 'abc' and TABLE.COL3 = 'hijk'
0
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.

 
LVL 7

Accepted Solution

by:
Ross Turner earned 2000 total points
ID: 38789107
SELECT

TABLE.COL1            AS [EXT_LA],

TABLE.COL2             AS [EXT_LAO],
 
TABLE.COL3            AS[EXT_LA#]

WHERE TABLE.COL2 = 'def' AND TABLE.COL3 in  ('def','hijk' )
0
 
LVL 40

Expert Comment

by:lcohan
ID: 38789108
Sorry I missed the FROM clause:

SELECT

TableName.COL1            AS [EXT_LA],
TableName.COL2             AS [EXT_LAO],
TableName.COL3            AS[EXT_LA#]

FROM TableName
WHERE TableName.COL2 = 'def' AND (TableName.COL3 = 'def' OR TableName.COL3 = 'hijk' )
0
 
LVL 8

Expert Comment

by:H
ID: 38789122
Select
TABLE.COL1 AS [EXT_LA], TABLE.COL2 AS [EXT_LAO],  TABLE.COL3 AS[EXT_LA#]
From TABLE
where
TABLE.COL2 = 'abc' and TABLE.COL3 = 'def'
or
TABLE.COL2 = 'abc' and TABLE.COL3 = 'hijk'
0
 

Author Closing Comment

by:Tech315
ID: 38789229
Thanks I Ross, appreaciate it
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 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