Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


concatenate rows using for xml path and new line feed carriage


concatenate rows using for xml path and new line feed carriage

Author
Message
julesbenone
julesbenone
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 17
based on your various recommendations i finally found a good workable solution without having to compromise that much with my early tsql code in the views. i stayed with my first tqsl as follow:

Stuff
(
(
Select ',' + City As [text()]
From #tempCityState
Where State = t.State
For Xml Path('')
)
, 1, 1, ''
) As Cities,

Please note this is part of a view that is used in a stored procedure that feeds an asp.net gridview

i made this adjustment in my stored procedures:

Replace(ViewName.Cities, ',' , '
') AS Cities

then after i added the HtmlEncode="False" property recommended by Sean in the BoundField.

by using this solution i didn't have to review rows concactenation tsql code(s) i have in several views and as a result affect others sto proc and frontends that connect to my sql server database.

To conclude i resolved my formatting problem by adding one additional property in my gridview boundfield and slightly adjusted a specific stored procedure that is only used by the asp.net application

Thanks to all who have contributed in this thread ... i think the topic can be closed now .. happy week end
waelmg50
waelmg50
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 0
This code is a modification to the above post to have the cities adjusted under each other

Create TABLE #tempCityState (State Varchar(5), City Varchar(50))

Insert Into #tempCityState
Select 'CO', 'Denver' Union
Select 'CO', 'Teluride' Union
Select 'CO', 'Vail' Union
Select 'CO', 'Aspen' Union
Select 'CA', 'Los Anggeles' Union
Select 'CA', 'Hanford' Union
Select 'CA', 'Fremont' Union
Select 'AK', 'Wynne' Union
Select 'AK', 'Nashville';
with States as (
select distinct
State
from
#tempCityState
)
select
State,
stuff((select CHAR(9) + ' ' + City + char(13) + char(10)
from #tempCityState tcs
where tcs.State = States.State
order by tcs.City
for xml path(''),TYPE).value('.','varchar(max)'), 1, 3, '') as Cities
from
States;
Drop table #tempCityState
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search