Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

sql query writing12 Expand / Collapse
Author
Message
Posted Tuesday, January 8, 2013 2:10 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 9:06 PM
Points: 206, Visits: 4,488
hi frieds i have small doubt in sql server plese tell me how to solve this
table data contains like
id , name
1 , a
1 , b
1 , c
2 , a
2 ,b
so i want out put like
id ,name
1 , abc
2 , ab
plese tell me how to write query in sql server
Post #1404059
Posted Tuesday, January 8, 2013 2:20 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 9:36 AM
Points: 5,230, Visits: 9,455
Does this help?

John
Post #1404066
Posted Tuesday, January 8, 2013 2:36 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 2:37 AM
Points: 1,608, Visits: 371
Hi,

Try this..
Hope this will help

SELECT OutTab.ID ,
Names =
STUFF ( ( SELECT ''+InrTab.Name
FROM [empInfo] InrTab
WHERE InrTab.id = OutTab.id
ORDER BY InrTab.id
FOR XML PATH(''),TYPE
).value('.','VARCHAR(MAX)')
, 1,0,SPACE(0))
FROM [empInfo] OutTab
GROUP BY OutTab.id;
Post #1404072
Posted Tuesday, January 8, 2013 2:43 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 14, 2014 4:48 AM
Points: 2,834, Visits: 3,950
Always post table defintion along with test data to get faster resultsl.people here steal their time to help others , sometimes they dont have time to frame everything here.please see the link below my signature.
hope this helps you

declare @t table 
(id int , chr char(1))

insert into @t
select 1, 'a' union
select 1, 'h' union
select 1, 'y' union
select 4, 'k' union
select 4, 'f'


select * from @t

select distinct id, STUFF((select '' + cast(chr as nvarchar(20)) from @t where id= t.id FOR XML PATH('')),1,0,'')
from @t t



-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1404076
Posted Tuesday, January 8, 2013 6:00 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 9:06 PM
Points: 206, Visits: 4,488
hi why here we use XML PATH('')),1,0,''
plese tell me some explnation to use of xml path
Post #1404195
Posted Tuesday, January 8, 2013 7:47 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 3:21 PM
Points: 13,083, Visits: 11,918
asranantha (1/8/2013)
hi why here we use XML PATH('')),1,0,''
plese tell me some explnation to use of xml path


BOL has the answer to this and MANY MANY more questions.

http://msdn.microsoft.com/en-us/library/ms178107.aspx


_______________________________________________________________

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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1404251
Posted Tuesday, January 8, 2013 8:06 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 8:48 PM
Points: 23,015, Visits: 31,536
This article should help some as well: http://www.sqlservercentral.com/articles/comma+separated+list/71700/.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1404264
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse