Re: How to concat the values in a column across rows.

From: Roji. P. Thomas (thoasroji_no_spam__at_gmail.com)
Date: 11/04/04


Date: Thu, 4 Nov 2004 12:10:27 +0530

The code is tested and working (atleast at my side)

-- 
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Colin Halliday" <colinh..at..kothes..com..au> wrote in message 
news:OaowTJjwEHA.3096@TK2MSFTNGP14.phx.gbl...
>I tried your code but I receive an "Error 156: Incorrect syntax near the 
>keyword 'THEN' "  error.
>
> Colin
>
> "Roji. P. Thomas" <thoasroji_no_spam_@gmail.com> wrote in message 
> news:uuLn62iwEHA.1452@TK2MSFTNGP11.phx.gbl...
>> Try this
>>
>>
>> USE Pubs
>> GO
>> --SELECT * FROM authors
>>
>> DECLARE @vchAuthors VARCHAR(400)
>> SET @vchAuthors = ''
>> SELECT @vchAuthors = @vchAuthors +
>> CASE WHEN @vchAuthors = '' THEN '' ELSE ', ' END + au_lname
>> FROM authors
>>
>> SELECT @vchAuthors
>>
>> -- 
>> Roji. P. Thomas
>> Net Asset Management
>> https://www.netassetmanagement.com
>>
>>
>> "vineetbatta" <vineetbatta@discussions.microsoft.com> wrote in message 
>> news:B1F54C51-FBE9-4D06-B3D8-1F2ACF5D9CCA@microsoft.com...
>>> Hi All,
>>>
>>> i am facing this problem...
>>>
>>> i have table "PLACEDATA"
>>> which has 2 columns
>>>
>>> ZIPCODE CITYNAME
>>> 56788 Seattle
>>> 98007 Bellevue
>>> 98009 Kirkland
>>>
>>>
>>> Is there any way that using ONE Query to get the following concatnate
>>>
>>> result like
>>>
>>> AllPlaces
>>> ----------
>>> Seattle,Bellevue,Kirkland
>>>
>>> I don't want to use while loop or cusors.
>>>
>>> -- 
>>> MCAD
>>> Vineet Batta
>>
>>
>
> 


Relevant Pages

  • Re: Insert Query taking ages....
    ... P. Thomas ... > table command in query analyser and it also just sits there for ages.... ... >>> Roji. ... >>> Net Asset Management ...
    (microsoft.public.sqlserver.programming)
  • Re: DISTINCT and LEFT JOIN problem
    ... P. Thomas ... >>> Roji. ... >>> Net Asset Management ... >>>>> community of SQL Server professionals. ...
    (microsoft.public.sqlserver.programming)
  • Re: searching with varying parameters
    ... "Roji. ... P. Thomas" wrote in message ... > Net Asset Management ... >> body, Search by attachment name, search if message has attachments). ...
    (microsoft.public.sqlserver.programming)
  • Re: Output parameters
    ... > Set CmdParams = Nothing ... > "Roji. ... P. Thomas" wrote in message ... >> Net Asset Management ...
    (microsoft.public.sqlserver.programming)
  • Re: Dynamic table name in query
    ... "Roji. ... P. Thomas" wrote in message ... >> Dynamic SQL, you could just explain your position or at least write the ... >>> You are trying to write a procedure without any cohesion at all. ...
    (microsoft.public.sqlserver.programming)