SQL 'IN' Statement
#1
Scooby Regular
Thread Starter
Join Date: Jun 2002
Location: Berkshire
Posts: 1,280
Likes: 0
Received 0 Likes
on
0 Posts
SQL 'IN' Statement
I'm trying to figure out how to use the contents of a cell in Excel to populate a SQL IN statement but can't figure it out. Does anybody know if this is possible?
Using a standard IN statement works fine...
And using one based on a cell works fine if theres just a single value in the cell...
But when I enter multiple values like this...
The query fails
Any ideas welcome
D
Using a standard IN statement works fine...
Code:
SELECT * FROM CRMtest2.dbo.AgendaItems AgendaItems WHERE (Region IN ('East','West'))
Code:
SELECT * FROM CRMtest2.dbo.AgendaItems AgendaItems WHERE (Region IN (?))
But when I enter multiple values like this...
The query fails
Any ideas welcome
D
#2
Scooby Regular
Join Date: Sep 2001
Location: A powerslide near you
Posts: 10,261
Likes: 0
Received 0 Likes
on
0 Posts
you need to seperate the valus in the cells. as it stands, it's ONE string rather than 3. You need a way to seperate them out, putting in the single ' quote marks appropriately. I'll let you figure out how to do this but it's not that difficult. beware of single quotes within strings tho
#3
Generate the whole select statement including the cell value as a text string and then run it, you will as Dracoro has said have to format the string with single quotes.
Thread
Thread Starter
Forum
Replies
Last Post
Mkhan
Non Scooby Related
14
09 August 2001 02:07 AM