SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sql query writing12


sql query writing12

Author
Message
asranantha
asranantha
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2258 Visits: 4717
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
John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)

Group: General Forum Members
Points: 80268 Visits: 17931
Does this help?

John
Aadhar Joshi
Aadhar Joshi
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2394 Visits: 451
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;
Bhuvnesh
Bhuvnesh
SSC-Dedicated
SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)

Group: General Forum Members
Points: 32394 Visits: 4079
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;-)
asranantha
asranantha
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2258 Visits: 4717
hi why here we use XML PATH('')),1,0,''
plese tell me some explnation to use of xml path
Sean Lange
Sean Lange
SSC Guru
SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)

Group: General Forum Members
Points: 148733 Visits: 18575
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 Modens 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)
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)

Group: General Forum Members
Points: 224280 Visits: 40419
This article should help some as well: http://www.sqlservercentral.com/articles/comma+separated+list/71700/.

Cool
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)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search