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 queres Expand / Collapse
Author
Message
Posted Sunday, January 20, 2013 10:04 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 4:16 AM
Points: 208, Visits: 4,498
Hi friends i have a small doubt in sql server plz tell me how to solve this one

How to Concat row data through sql server?
Source:
Ename EmpNo
stev 100
methew 100
john 101
tom 101
output like:
Ename EmpNo
Stev methew 100
John tom 101
plese tell me how to write query in sql server
Post #1409349
Posted Monday, January 21, 2013 1:37 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:47 AM
Points: 2,837, Visits: 3,953
it will be easy for people if you post the table defifntion (create stmt) along with some sampoled data plus expected output.people generally steal some time from their busy scehdules to help other people and often they dont have time to frame everything on theri own (and sometime people are too lazy like me which are reluctant to do this ) so better do these things to get the result faster. See link in my signature below

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1409403
Posted Monday, January 21, 2013 1:41 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, June 16, 2014 5:32 AM
Points: 55, Visits: 158
Looping on every row is not a good practice especially on large data. But it will give you an idea where to start
Post #1409407
Posted Monday, January 21, 2013 2:34 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 5:47 AM
Points: 13,323, Visits: 10,192
Here's a nice comprehensive article:
Concatenating Row Values in Transact-SQL




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1409436
Posted Monday, January 21, 2013 3:26 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:47 AM
Points: 2,837, Visits: 3,953
see this
declare @t table (Ename nvarchar(200), EmpNo int)

insert into @t

select 'Bhuvnesh' , 11 union
select 'girth' , 11 union
select 'pooja' , 12 union
select 'rana' , 12

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



-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1409460
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse