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)
 Passing a CSV to be used in an 'In' clause

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-07-15 : 08:27:16
Adam Flynn writes "I've read your CSV articles, but here's a show-stopping problem I'm not sure can be tackled. But I sure hope you can. I want to pass a CSV list of integer values (a string which is a comma-delimited list of id values for a table) and use that in an in clause. Essentially:

create procedure sp_Test
@test varchar(50)
as
set nocount on

select document_id, document_name
from document
where document_id in (@test)

set nocount off
go

sp_Test '2,3,4'

But of course SQL server interperates the list as a single string, and throws an error because the implicit conversion of string to int fails. And as yet I can't figure out a way to write function that would returns these values in a form that can be dealt with because if I want to pass a list it would have to be in string format (okay I think I could use a multi-statement table-valued function to construct a table of the values and return a selection from it, but I really would prefer a simplier and faster solution). Do you have any suggestions?"

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2002-07-15 : 08:27:16
We've got a link to this in our Frequently Asked Questions page (http://www.sqlteam.com/FAQ.asp).
Go to Top of Page
   

- Advertisement -