select 字段ID,字段2,字段3,字段4,stuff((select ','+字段23 from table2 where table2.字段ID=tb1.字段ID for xml path('')),1,1,'') 字段23 ,stuff((select ','+字段33 from table3 where table3.字段ID=tb1.字段ID for xml path('')),1,1,'') 字段33,stuff((select ','+字段43 from table4 where table4.字段ID=tb1.字段ID for xml path('')),1,1,'') 字段43 ,stuff((select ','+字段53 from table5 where table5.字段ID=tb1.字段ID for xml path('')),1,1,'') 字段53 from table1 tb1 where tb1.字段id in (select 字段id from table3 where 字段33='张三' )
------最佳解决方案-------------------- stuff((select ','+字段33 from table3 where table3.字段ID=tb1.字段ID for xml path('')),1,1,'') 字段33
改为张三就行了 ------其他解决方案-------------------- stuff((select ','+字段33 from table3 where table3.字段ID=tb1.字段ID and 字段33 in('张三') for xml path('')),1,1,'') 字段33 ------其他解决方案-------------------- 呵呵 stuff这个关键字看来还是很有用的嘛? ------其他解决方案--------------------
嗯,将字段33那一列为"张三" ------其他解决方案--------------------
stuff((select ','+字段33 from table3 where table3.字段33='张三' for xml path('')),1,1,'') 字段33
这样?