From: Luigi on
Hi all,
having a variable with values separated by ;
how can I split it to execute a stored procedure for each of them?

Like

declare @MyVariable varchar(50)
set @MyVariable = 'value1;value2;value3'

and exec MyStored for each of value1, value2, value3, etc.

Thanks a lot.

Luigi

From: Hugo Kornelis on
On Fri, 5 Feb 2010 01:18:01 -0800, Luigi wrote:

>Hi all,
>having a variable with values separated by ;
>how can I split it to execute a stored procedure for each of them?
>
>Like
>
>declare @MyVariable varchar(50)
>set @MyVariable = 'value1;value2;value3'
>
>and exec MyStored for each of value1, value2, value3, etc.
>
>Thanks a lot.
>
>Luigi

Hi Luigi,

See http://www.sommarskog.se/arrays-in-sql.html

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
From: Luigi on
"Hugo Kornelis" wrote:
> Hi Luigi,
>
> See http://www.sommarskog.se/arrays-in-sql.html

Thank you Hugo, it's a good starting point.

Luigi
From: Plamen Ratchev on
Instead of splitting the variable you can design the stored procedure to take a table-valued parameter (on SQL Server
2008) or XML, and process all values at once (instead of multiple SP executions).

--
Plamen Ratchev
http://www.SQLStudio.com
From: Luigi on
"Plamen Ratchev" wrote:

> Instead of splitting the variable you can design the stored procedure to take a table-valued parameter (on SQL Server
> 2008) or XML, and process all values at once (instead of multiple SP executions).

Hi Plamen, unfortunately I must adhere at SQL Server 2000 T-SQL
specifications.

Luigi