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)
 How do i add a variable ?

Author  Topic 

missMac
Posting Yak Master

124 Posts

Posted - 2008-11-15 : 18:12:29
Hello,
How do i add an extra column to this statement



Select @csv = isnull(@csv + ',', '') + Receipient
From history

I want to add another column as thus

Select @csv = isnull(@csv + ',', '') + Receipient, deliver
From history

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-16 : 05:04:00
you want to add it to csv? or just include it among select?
Go to Top of Page

missMac
Posting Yak Master

124 Posts

Posted - 2008-11-16 : 06:06:44
I want value as thus

1st statement returns

254254254,254254254254,2542542542542,2452452452

2nd statement should return

254254254/tkizer,254254254254/peso,2542542542542/visakh,2452452452/missmac

How can i achieve this ? thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-16 : 06:34:21
[code]Select @csv = isnull(@csv + ',', '') + Receipient + '/'+ deliver
From history[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-16 : 06:36:12
and just in case Receipient & deliver can contain null values, modify like below

Select @csv = isnull(@csv + ',', '') + coalesce(Receipient,0) + '/'+ coalesce(deliver,0)
From history

Go to Top of Page

missMac
Posting Yak Master

124 Posts

Posted - 2008-11-16 : 07:28:01
Thank you sir.

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-16 : 11:50:52
Cheers
Go to Top of Page
   

- Advertisement -