[AccessD] Stored Procedure SQL IN Clause

Brett Barabash BBarabash at TappeConstruction.com
Mon Feb 16 11:44:40 CST 2004


Normally for statements like these it is necessary to concatenate strings
together and use the EXEC keyword to run the resulting string.  For example:

CREATE PROCEDURE uspResidenceTypeList
@InClause Varchar(200)
AS
EXEC ('SELECT * FROM tblClient WHERE ResidenceType IN (' + @InClause + ')')

Let me know if you find another way of doing this.

-----Original Message-----
From: Robert L. Stewart [mailto:rl_stewart at highstream.net]
Sent: Monday, February 16, 2004 10:16 AM
To: accessd at databaseadvisors.com
Cc: dba-sqlserver at databaseadvisors.com
Subject: [AccessD] Stored Procedure SQL IN Clause


All,

The end of last week, I was working on a stored procedure in SQL Server.  I 
wanted it to be able to pass in information via a parameter to populate an 
IN clause in the SQL statement so I could use a multi-select list box for 
the control on the form.

Here is what I was trying:

I have a list of residence types (house, hotel, mobile home, homeless, 
etc.).  I wanted to be able to select one or more in the list box.

The Stored Procedure looked something like this:

CREATE PROCEDURE uspResidenceTypeList
@InClause Varchar(200)
AS
SELECT *
FROM tblClient
WHERE (ResidenceType IN(@InClause)

This works for a single value, i.e. 'Homeless', but it returns no records 
when I pass in multiple values.

Does someone have any ideas about what I can do to get this to work?

Thanks,

Robert

Note Cross posted to dba-sqlserver at databaseadvisors.com

--------------------------------------------------------------------------------------------------------------------
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom
they are addressed.
If you have received this email in error please notify the
originator of the message. This footer also confirms that this
email message has been scanned for the presence of computer viruses.

Any views expressed in this message are those of the individual
sender, except where the sender specifies and with authority,
states them to be the views of Tappe Construction Co.

Scanning of this message and addition of this footer is performed
by SurfControl E-mail Filter software in conjunction with 
virus detection software.




More information about the AccessD mailing list