sql queres

  • 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

  • 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;-)

  • Looping on every row is not a good practice especially on large data. But it will give you an idea where to start 😀

  • Here's a nice comprehensive article:

    Concatenating Row Values in Transact-SQL[/url]

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • 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;-)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply