sql server - SQL same unit between two tables needs order numbers in 1 cell -


i have 2 tables:

select unitid dbo.tblunits  select unitid, workordernumber dbo.tblworkorders 

i need display unitid's dbo.tblunits in 1 column diplay workorders seperated comma.

so here sample data: dbo.tblunits:

unitid 123 156 178 

dbo.tblworkorders

unitid workordernumber 123        1 123        2 156        4 178        5 178        9 178        10 

i have use tblunits table because pulling more data final result want show this:

unitid   workordernumber 123         1,2 156         4  178         5,9,10 

any ideas?

thanks

select      unitid,      stuff((select ', ' + convert(varchar, workordernumber)             tblworkorders t2 t1.unitid = t2.unitid             xml path('')),           1,2,'') workordernumbers tblworkorders t1 group unitid 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -