Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i have this table

---------
ID | Name
--------
1 | David is a men
2 | Jan is interest
3 | Juli is a women
1 | Mike is good
---------

i wanna get this table from up table :

---------
ID | Name
--------
1 | David is a men -- Mike is good
2 | Jan is interest
3 | Juli is a women
---------

please guide me ...
Posted

1 solution

Try this.
SQL
SELECT   ID, LEFT([Name], LEN([Name]) - 1) as [Name]
            FROM  ( SELECT  DISTINCT ID 
                       FROM  tablename )  AS A
	          
 OUTER APPLY ( SELECT  RTRIM(B.Name)  + ' -- '
                 FROM  tablename B WHERE A.ID = B.ID 
                  FOR  XML PATH('') ) AS C ([Name])
 
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