Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

SQL 'IN' Statement

Thread Tools
 
Search this Thread
 
Old May 5, 2007 | 05:11 PM
  #1  
djuk's Avatar
djuk
Thread Starter
Scooby Regular
 
Joined: Jun 2002
Posts: 1,280
Likes: 0
From: Berkshire
Default 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...

Code:
SELECT *
FROM CRMtest2.dbo.AgendaItems AgendaItems
WHERE (Region IN ('East','West'))
And using one based on a cell works fine if theres just a single value in the cell...

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
Reply
Old May 5, 2007 | 08:24 PM
  #2  
Dracoro's Avatar
Dracoro
Scooby Regular
 
Joined: Sep 2001
Posts: 10,261
Likes: 0
From: A powerslide near you
Default

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
Reply
Old May 5, 2007 | 09:26 PM
  #3  
J4CKO's Avatar
J4CKO
Scooby Regular
iTrader: (1)
 
Joined: Jan 2003
Posts: 19,384
Likes: 1
Default

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.
Reply
Old May 5, 2007 | 10:54 PM
  #4  
djuk's Avatar
djuk
Thread Starter
Scooby Regular
 
Joined: Jun 2002
Posts: 1,280
Likes: 0
From: Berkshire
Default

Sorted, Thanks guys
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
stevem2k
Non Scooby Related
8
Jul 6, 2011 11:11 PM
HHxx
Computer & Technology Related
3
Jan 16, 2002 05:06 PM
Mkhan
Non Scooby Related
14
Aug 9, 2001 02:07 AM
stevem2k
Non Scooby Related
3
Jul 5, 2001 05:39 PM
SDB
Non Scooby Related
2
May 26, 2001 11:55 PM




All times are GMT +1. The time now is 10:22 AM.