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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 ListAgg Equivalent in MSSQL
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Gerald30
Starting Member

Philippines
49 Posts

Posted - 04/02/2013 :  21:56:40  Show Profile  Reply with Quote
Hello All,

Can you tell me what is the MSSQL Equivalent of List Tag?

What I want to achieve is concat all the ID base on its Code.


Example

Code | ID
001 | 80011,80010,80003
002 | 80014,80026,80031

Here is the sample code that I made.

select
distinct
b.Emt_CostCenterCode,
stuff((select','+ Emt_EmployeeID from T_EmployeeMaster a where a.Emt_EmployeeID = b.Emt_EmployeeID For XML PATH('')),1,1,'')
from T_EmployeeMaster b
group by b.Emt_CostCenterCode,b.Emt_EmployeeID


Please help.

Thanks

Edited by - Gerald30 on 04/02/2013 21:57:37

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/03/2013 :  01:22:05  Show Profile  Reply with Quote

select
b.Emt_CostCenterCode,
stuff((select','+ CAST(a.Emt_EmployeeID AS varchar(10)) 
       from T_EmployeeMaster a 
       where a.Emt_CostCenterCode = b.Emt_CostCenterCode 
       For XML PATH('')),1,1,'')
from (select distinct Emt_CostCenterCode from T_EmployeeMaster) b


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Gerald30
Starting Member

Philippines
49 Posts

Posted - 04/03/2013 :  02:02:21  Show Profile  Reply with Quote
Thank you sir.

So What I have been missing is the cast part.

Now I understand.

Thanks again.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/03/2013 :  02:04:51  Show Profile  Reply with Quote
yep....you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.06 seconds. Powered By: Snitz Forums 2000