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)
 WHERE Table.Field IN(@NamedParameter) ?

Author  Topic 

jhakkesteegt
Starting Member

3 Posts

Posted - 2007-07-12 : 06:20:32
Can anyone tell me whether it is at all possible to use a named parameter in an IN() statement?

I have not been able to find any documentation or articles that talk about IN() statements and parameters in the same query.

I would like to use this in conjunction with VB.NET's SQLDataAdapter, (a good start to avoid sql injection attacks)

cas_o
Posting Yak Master

154 Posts

Posted - 2007-07-12 : 06:27:24
Only with a subquery or dynamic sql.

SUBQUERY:
=========
select * from table where field in (select field from table where field = criteria)


DYNAMIC:
========
declare @list = varchar(4000)
declare @sql = varchar(4000)

select @list = '1,2,3,4'

select @sql = 'select * from table where field in (' + list + ')'

EXEC(@sql)

;-]... Quack Waddle
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-12 : 06:34:11

http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jhakkesteegt
Starting Member

3 Posts

Posted - 2007-07-12 : 06:34:58
Thanks cas_o.

It answers my question, but unfortunately in the negative.
I'll just have to build some parameter checking into my app...
Go to Top of Page

jhakkesteegt
Starting Member

3 Posts

Posted - 2007-07-12 : 07:13:33
Thanks Madhivanan for the good article. It definitely applies to my problem, and no wonder I didn't find it myself.

Once again, unfortunately I can not use this type of solution in my app. So I'll just have to revert to coding.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-12 : 08:11:38
<<
unfortunately I can not use this type of solution in my app.
>>

Why?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -