Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VarChar variable with NOT IN 1

Status
Not open for further replies.

RobHVB6Sql

Programmer
May 20, 2002
77
AU
I am writing a stored procedure for a report.
The user is shown a list of all clients in a grid on a form. They then remove the database clients they do not want.

The procedure selects the basic list of clients, then I wish to remove some clients from the working table.
Ie
Code:
SELECT PersonID, aa, bb, cc from tblWhatever
WHERE PersonID NOT In (@VarChar)
The varchar is sent like this "231, 240, 250".

Do I need to loop though the working table to delete each personID in turn?
Or can I use @VarChar in the select statement?

Some code examples would be great, thanks in advance.

Rob Hasard
Data Manager -Genetic Services
(VB6 /SQL 7.0)
 
Use a technique called 'dynamic sql', this has many uses - search the forums for more info. Here is an example to get you started

Code:
declare @cmd varchar(200)
set @cmd = 'SELECT * from acc WHERE accid NOT In (' + @VarChar + ')'
exec(@cmd)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top