• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1002
  • Last Modified:

sql select from list syntax help

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
pmtolk1
Asked:
pmtolk1
  • 2
  • 2
2 Solutions
 
brad2575Commented:
You would have to do something like this:

select (1)

UNION

select (2)

UNION

select (3)
0
 
pmtolk1Author Commented:
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
 
reb73Commented:
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
 
reb73Commented:
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
 
pmtolk1Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now