Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL in Statement in SQL Server 7.0

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-08-26 : 11:28:07
Jason writes "I have the following problem:

A web form contains a multiple list box of company names whose value when selected is a supplierID. I wish to pass this information into a stored procedure which is a little like this:

create proc usp_test
@SupplierID varchar(1000)
as

select * from Supplier
where supplierID in (@SupplierID)

How can I do this without building dynamic sql?

i.e.
declare @sql varchar(1000)
set @sql = 'SELECT * FROM supplier where supplierID in (' + @SupplierID + ')'

The table is very large so I don't think dynamic SQL is the answer. Also the number of companies selected is put to the user, i.e. variable.

Thanks in advance"

nr
SQLTeam MVY

12543 Posts

Posted - 2002-08-26 : 12:17:46
comma delimitted list?

select * from Supplier
where ',' + @SupplierID + ',' like '%,' + convert(varchar(20),supplierID) + ',%'

but dynamic sql would probably be faster.

I usually do this by putting the IDs into a temp table and joining to that.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -