SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help in Logic to Concat
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

madhuvrk
Starting Member

2 Posts

Posted - 08/22/2014 :  03:52:59  Show Profile  Reply with Quote
Hello everyone,

This is the requirement,I have a table like this below :

Actual table: Item_Seller

item_id |seller_name
-----------------------
12310450 |Pro Team
12310450 |CSNStores.com
12310451 |CSNStores.com
12310452 |CSNStores.com
12310452 |Pro Team
12310453 |Pro Team
12310691 |CSNStores.com
12310691 |Pro Team
12310692 |CSNStores.com
12310692 |Pro Team

The 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.com
12310451 |CSNStores.com
12310452 |CSNStores.com,Pro Team
12310453 |Pro Team
12310691 |CSNStores.com,Pro Team
12310692 |CSNStores.com,Pro Team


Thanks
Madhuvrk

ahmeds08
Aged Yak Warrior

India
675 Posts

Posted - 08/22/2014 :  05:58:55  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
can you try this
SELECT item_id,
MAX(CASE WHEN rk = 1 THEN seller_name END) AS value1,
MAX(CASE WHEN rk = 2 THEN seller_name END) AS value2
into #temp1
FROM (SELECT item_id, seller_name,
ROW_NUMBER() OVER(PARTITION BY item_id
order by item_id) AS rk
FROM item_seller) AS A
GROUP BY item_id
select item_id,value1+','+value2 as concat_seller from #temp1
drop table #temp1


Javeed Ahmed
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000