Solved

TSQL multiple select statement

Posted on 2013-01-17
7
416 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 39

Expert Comment

by:lcohan
Comment Utility
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
Comment Utility
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
Comment Utility
where
TABLE.COL2 = 'abc' and TABLE.COL3 = 'def'
or
TABLE.COL2 = 'abc' and TABLE.COL3 = 'hijk'
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 7

Accepted Solution

by:
Ross Turner earned 500 total points
Comment Utility
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 39

Expert Comment

by:lcohan
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks I Ross, appreaciate it
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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

771 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

13 Experts available now in Live!

Get 1:1 Help Now