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 2005 Forums
 Transact-SQL (2005)
 comma seperated list to stored proc

Author  Topic 

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2010-02-09 : 21:41:04
Below is where condition and I passed comma seperated list (x) from front end to @test.But It returns null even the value is inside.
dim x as string = "aa,bb,cc"

(col1 IN(' + @test + ') OR @test IS NULL)

Where is it wrong ?

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-09 : 21:57:17
read this

http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
http://www.sommarskog.se/arrays-in-sql-2005.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2010-02-09 : 22:10:06
I just followed it.

quote:
Originally posted by khtan

read this

http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
http://www.sommarskog.se/arrays-in-sql-2005.html


KH
[spoiler]Time is always against us[/spoiler]



Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-09 : 22:14:23
pls post your full query


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-02-09 : 23:04:04
Since you are passing a string value and not integer value, i feel that all individual value should be in single quotes.

Just try by adding the below statement to your code before calling it dynamically.

Set @test = '''' + Replace(@test, ',' , ''',''' ) + ''''

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-10 : 00:19:36
quote:
Originally posted by kwikwisi

Below is where condition and I passed comma seperated list (x) from front end to @test.But It returns null even the value is inside.
dim x as string = "aa,bb,cc"

(col1 IN(' + @test + ') OR @test IS NULL)

Where is it wrong ?

Thanks


are you asking about sql or vb? sql doesnt have dim.
if sql it should be

',' + @test + ',' LIKE '%,'+ col1 + ',%'

------------------------------------------------------------------------------------------------------
SQL Server MVP
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2010-02-10 : 04:21:59
Yes, I know SQL doesnt have Dim .
I just let you know how I passed the string value from VB.Net.

Thanks.
quote:
Originally posted by visakh16

quote:
Originally posted by kwikwisi

Below is where condition and I passed comma seperated list (x) from front end to @test.But It returns null even the value is inside.
dim x as string = "aa,bb,cc"

(col1 IN(' + @test + ') OR @test IS NULL)

Where is it wrong ?

Thanks


are you asking about sql or vb? sql doesnt have dim.
if sql it should be

',' + @test + ',' LIKE '%,'+ col1 + ',%'

------------------------------------------------------------------------------------------------------
SQL Server MVP

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-10 : 04:25:11
ok and does my suggestion work in sql?

------------------------------------------------------------------------------------------------------
SQL Server MVP
Go to Top of Page
   

- Advertisement -