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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 ListAgg Equivalent in MSSQL

Author  Topic 

Gerald30
Yak Posting Veteran

62 Posts

Posted - 2013-04-02 : 21:56:40
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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-03 : 01:22:05
[code]
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
[/code]

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

Gerald30
Yak Posting Veteran

62 Posts

Posted - 2013-04-03 : 02:02:21
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

52326 Posts

Posted - 2013-04-03 : 02:04:51
yep....you're welcome

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

- Advertisement -