Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql select from list syntax help

Posted on 2009-05-06
5
Medium Priority
?
996 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 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