sql server 2008 - Need SQL Query to coallate data from two tables in a desired format -
i have table clientdetails of 2 columns clientid
, associated branchcode
in separate columns. need table distinct branches table in column & clientids associated branch in column ',' seperated. e.g.> table1:
branch | clientids b001 | cli001 b001 | cli002 b001 | cli003
result needed:
branch | clientids b001 | cli001,cli002,cli003
what best optimized way data record count quite large. need these columns bind 2 comboboxes of win form.
regards, ashish
in sql server 2008,,
select branch, stuff((select ',' + clientids clientdetails a.branch = t.branch xml path('')), 1, 1, '') clientid clientdetails t group branch
Comments
Post a Comment