Home All Groups Group Topic Archive Search About

flatten rows into a variable

Author
1 Jul 2005 10:49 AM
MrMarteng
Hi!
Does anyone know how to flatten rows into a variable using sql in a
stored procedure?

Such as getting a rowset  like this :

SELECT ID FROM SOMETABLE


ID
----------
1
2
3
4
5
6
7


And somehow get a variable containing 1234567

Regards Marteng

Author
1 Jul 2005 12:45 PM
Rudi
Declare @ids varchar(8000)
Set @ids = ''
SELECT @ids = @ids + CONVERT(varchar, ID) + ' '
FROM SOMETABLE
Select @ids

Show quote
"MrMarteng" <mrmart***@hotmail.com> wrote in message
news:uawEGqifFHA.484@TK2MSFTNGP14.phx.gbl...
> Hi!
> Does anyone know how to flatten rows into a variable using sql in a stored
> procedure?
>
> Such as getting a rowset  like this :
>
> SELECT ID FROM SOMETABLE
>
>
> ID
> ----------
> 1
> 2
> 3
> 4
> 5
> 6
> 7
>
>
> And somehow get a variable containing 1234567
>
> Regards Marteng
>
>

AddThis Social Bookmark Button