May 1, 2012 at 12:03 pm
Hey Guy,
please i need one more times ur help. I try to join many rows in one rows without success. for example:
Name | is the father of
Erick | patricia
Michael | leonie
Erick | Anne
Stephane | Sabine
Stephane | emilie
i want to have after as a new view something like this:
Name | is the father of
Erick | patricia ,Anne
Stephane | Sabine , emilie
Michael | leonie
is somthing like this possible in sql ?How can i do to make it if it si possible?
can somebody explain me please.
thx.
Stephane
May 1, 2012 at 12:05 pm
Yes it is possible.
Jared
CE - Microsoft
May 1, 2012 at 12:12 pm
+1. Yes, it is possible.
If you would take the time to read the first article I reference below in my signature block and follow the instructions regarding what and how to post the information we need to help you, you will get an answer very quickly.
May 1, 2012 at 12:18 pm
Lynn Pettis (5/1/2012)
+1. Yes, it is possible.If you would take the time to read the first article I reference below in my signature block and follwo the instructions regarding what and how to post the information we need to help you, you will get an answer very quickly.
its possible by using a pivot table or cross tabs. the link is for PIVOT. if you post the DDL and Sample data you will most likely get some nice tested code.
http://msdn.microsoft.com/en-us/library/ms177410.aspx
For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]
Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
Jeff Moden's Cross tab and Pivots Part 1[/url]
Jeff Moden's Cross tab and Pivots Part 2[/url]
May 1, 2012 at 12:20 pm
capn.hector (5/1/2012)
Lynn Pettis (5/1/2012)
+1. Yes, it is possible.If you would take the time to read the first article I reference below in my signature block and follow the instructions regarding what and how to post the information we need to help you, you will get an answer very quickly.
its possible by using a pivot table or cross tabs. the link is for PIVOT. if you post the DDL and Sample data you will most likely get some nice tested code.
http://msdn.microsoft.com/en-us/library/ms177410.aspx
Doesn't look like a pivot. Looks like a concatenation of multiple values to a single column.
May 1, 2012 at 12:26 pm
Something like this should do the trick.
;with FamilyTree(ParentName, ChildName) as
(
select 'Erick', 'patricia' union all
select 'Michael', 'leonie' union all
select 'Erick', 'Anne' union all
select 'Stephane', 'Sabine' union all
select 'Stephane', 'emilie'
)
select ParentName, STUFF((select ', ' + ChildName
from FamilyTree ft2
where ft.ParentName = ft2.ParentName
order by ft2.ChildName desc
for xml path('')), 1, 1, ' ')
from FamilyTree ft
group by ParentName
order by ft.ParentName
--EDIT--
Added the order by to the main query to ensure the order of results.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 1, 2012 at 12:30 pm
thanks for ur help. I'm Sorry for a post. i will read all the rules and i will no more do a same failure.
thx guy again.
see you then.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply