Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,
I saved Values like this

1 AndhraPradesh 22 Vizianagaram Denkada
1 AndhraPradesh 22 Vizianagaram Bhoghapuram
1 AndhraPradesh 22 Vizianagaram Pusapatirega
1 AndhraPradesh 21 Visakhapatnam Bheemunipatnam
1 AndhraPradesh 21 Visakhapatnam Araku Valley
1 AndhraPradesh 21 Visakhapatnam Anakapalle
1 AndhraPradesh 21 Visakhapatnam Gajuwaka
1 AndhraPradesh 21 Visakhapatnam Chodavaram


But i want output like this

1 AndhraPradesh 22 Vizianagaram Denkada
Bhogapuram
Pusapatirega
21 Visakhapatnam Araku Valley
Gajuwaka

is it possible r not?
can any one solve it plz
Thanks & Regards
Hari
Posted
Updated 27-Nov-12 2:13am
v3
Comments
[no name] 27-Nov-12 8:04am    
What have you tried ? And you want column name or mentioned value ??

Based upon your illustration, I think the answer you are looking for is a qualified "sort of". What it looks like you want is a new row with just the last column's data when the first part is duplicated. Sure, you could blank the other columns out but what's the point. Besides, the SQL statement to do so would be ugly. However, if you want all of the values for that last column to be in one column (so each person gets one row and the last column has n number of entries in it), you can do so using a CROSS APPLY statement. Here is a forum post that will help you out:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=102429[^]

The statement from that post that would probably be what you want is this one:
SQL
SELECT p.ASSIGNNUM,p.DESC,p.STARTDATE,LEFT(el.EmpList,LEN(el.EmpList)-1)
FROM #TableParent p
CROSS APPLY (SELECT EMPLOYEENUM + ',' AS [text()]
             FROM #TableChild
             WHERE ASSIGNNUM =p.ASSIGNNUM 
             FOR XML PATH('')) el(EmpList)

Obviously you would need to modify it to fit your needs but the end result would be a comma-delimited list of values in the last column.
 
Share this answer
 
This is my solution:

SQL
Select Distinct o.State, o.City,

(

Select I.Mandal + ', ' From Mandal I

Where I.StateID = o.StateID and I.CityID = o.CityID

For XML Path('')

) [Combined Data]

from Country O
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900