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 08, 2013 2:10 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 7:08 AM
Points: 166, Visits: 3,874
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 08, 2013 2:20 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Tuesday, June 04, 2013 7:03 AM
Points: 4,443, Visits: 7,249
Does this help?

John
Post #1404066
Posted Tuesday, January 08, 2013 2:36 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Yesterday @ 1:15 AM
Points: 1,453, Visits: 255
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 08, 2013 2:43 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, June 13, 2013 7:03 AM
Points: 2,562, Visits: 3,453
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----------
While 1 = 1 (Learning SQL....)
Click to get fast response of your post
Post #1404076
Posted Tuesday, January 08, 2013 6:00 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 7:08 AM
Points: 166, Visits: 3,874
hi why here we use XML PATH('')),1,0,''
plese tell me some explnation to use of xml path
Post #1404195
Posted Tuesday, January 08, 2013 7:47 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 3:12 PM
Points: 8,957, Visits: 8,523
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
Post #1404251
Posted Tuesday, January 08, 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 @ 1:13 PM
Points: 21,832, Visits: 27,850
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