Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
madhuvrk
Starting Member
2 Posts |
Posted - 2014-08-22 : 03:52:59
|
Hello everyone,This is the requirement,I have a table like this below :Actual table: Item_Selleritem_id |seller_name-----------------------12310450 |Pro Team12310450 |CSNStores.com12310451 |CSNStores.com12310452 |CSNStores.com12310452 |Pro Team12310453 |Pro Team12310691 |CSNStores.com12310691 |Pro Team12310692 |CSNStores.com12310692 |Pro TeamThe requirement is to concatenate seller_name in the table like below output, this should not be performed using a stored procedure. I need help in writing a select query to display the below output.item_id |seller_name_concat------------------------------12310450 |Pro Team,CSNStores.com12310451 |CSNStores.com12310452 |CSNStores.com,Pro Team12310453 |Pro Team12310691 |CSNStores.com,Pro Team12310692 |CSNStores.com,Pro TeamThanksMadhuvrk |
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2014-08-22 : 05:58:55
|
can you try thisSELECT item_id,MAX(CASE WHEN rk = 1 THEN seller_name END) AS value1,MAX(CASE WHEN rk = 2 THEN seller_name END) AS value2into #temp1FROM (SELECT item_id, seller_name,ROW_NUMBER() OVER(PARTITION BY item_idorder by item_id) AS rkFROM item_seller) AS AGROUP BY item_id select item_id,value1+','+value2 as concat_seller from #temp1drop table #temp1Javeed Ahmed |
|
|
|
|
|
|
|