我进行查询以获取客户信息:
例如,我想知道客户制作订单的目录,并在查询后得到:
client1 ABC
client1 BCD
client1 DDD
所以我想把所有这些目录分成一行:
client1 ABC, BCD, DDD
SELECT clientid, catalogue FROM A
INNER JOIN B ON A.A=B.A
WHERE orderdate > '20110101'
是否可以这样做?
我应该用它做什么?
谢谢!
答案 0 :(得分:1)
尝试
State (Tablename)
City (Columnname)
Chennai
Madurai
Coimbatore
declare @retstr varchar(8000)
select Top 5 @retstr =
COALESCE(@retstr + ';','') + City
from State print @retstr Result:
Chennai;Madurai;Coimbatore