[dba-SQLServer] Stored Procedure SQL IN Clause

Nicholson, Karen knicholson at gpsx.net
Mon Feb 16 15:30:33 CST 2004


Can you put in the percentage sign to include a longer string?
The way you have it, the procedure will look for an exact match.

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


-----Original Message-----
From: Haslett, Andrew [mailto:andrew.haslett at ilc.gov.au]
Sent: Monday, February 16, 2004 4:28 PM
To: 'dba-sqlserver at databaseadvisors.com'
Subject: RE: [dba-SQLServer] Stored Procedure SQL IN Clause


Test it by manually inserting the same values into the WHERE clause to see
if its returning any results.

What format are you passing your criteria as? 

-----Original Message-----
From: Robert L. Stewart [mailto:rl_stewart at highstream.net] 
Sent: Tuesday, 17 February 2004 2:46 AM
To: accessd at databaseadvisors.com
Cc: dba-sqlserver at databaseadvisors.com
Subject: [dba-SQLServer] 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


_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com

IMPORTANT - PLEASE READ ******************** 
This email and any files transmitted with it are confidential and may 
contain information protected by law from disclosure. 
If you have received this message in error, please notify the sender 
immediately and delete this email from your system. 
No warranty is given that this email or files, if attached to this 
email, are free from computer viruses or other defects. They 
are provided on the basis the user assumes all responsibility for 
loss, damage or consequence resulting directly or indirectly from 
their use, whether caused by the negligence of the sender or not.
_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com



More information about the dba-SQLServer mailing list