Solved

sql select from list syntax help

Posted on 2009-05-06
5
972 Views
Last Modified: 2012-05-06
I want to do a select

where I have a comma separated list

select
(1),
(2)

select
1,2,3

but these keep selecting into new columns
how do I write it so it selects each one into a new row

like
- no column name
1 1
2 2
3 3

0
Comment
Question by:pmtolk1
  • 2
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
brad2575 earned 125 total points
ID: 24314110
You would have to do something like this:

select (1)

UNION

select (2)

UNION

select (3)
0
 
LVL 2

Author Comment

by:pmtolk1
ID: 24314327
I know you can do it as a list I just forgot the syntax
I am not crazy I have done this before damn cinco de mayo


If I have a long list
1,2,3,4,5,6..n

I should be able write

Select ((1,2,3,4,5,6..n)) somehow to get it to select as Rows right?
0
 
LVL 25

Expert Comment

by:reb73
ID: 24314427
You can do it with a UDF (User Defined Function) or a CTE (if on MS SQL Server 2005 or above).. What version of MS SQL Server is your backend?
0
 
LVL 25

Assisted Solution

by:reb73
reb73 earned 125 total points
ID: 24314511
Brandon Galderisi's post in the link (fn_DelimitedToTable) below should do the trick for you -

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_23774477.html#a22605889
0
 
LVL 2

Author Comment

by:pmtolk1
ID: 24314645
I remember the syntax now

SELECT [ID]
  FROM [DB].[dbo].[oops]
where ID in
(
1,2,3
)

which of course isnt what I wanted so I guess that means you guys are right?
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Join multiple pivot queries 2 16
SQL Result Set to XML 4 36
export sql results to csv 6 34
T-SQL Default value in Select? 5 22
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

815 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

12 Experts available now in Live!

Get 1:1 Help Now