Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

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

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


Aged Yak Warrior

737 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,
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  
 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.04 seconds. Powered By: Snitz Forums 2000