Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sql select from list syntax help

Posted on 2009-05-06
5
Medium Priority
?
998 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 375 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 375 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
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. …
Suggested Courses

971 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