SQLServer根据相同字段循环某个字段
(Select STUFF(cast((Select '、'+oac.CITY_NAME FROM ORDER_AREA_CITY oac
where oac.ORDER_AREA_DETAIL_ID = oad.ORDER_AREA_DETAIL_ID FOR XML PATH('')) as varchar(1000)),1,1,'')) as PROV_NAMES,
关键就是这一句,仔细看下就懂了,感觉比较实用:
(Select '、'+oac.CITY_NAME FROM ORDER_AREA_CITY oac
where oac.ORDER_AREA_DETAIL_ID = oad.ORDER_AREA_DETAIL_ID FOR XML PATH('')) as varchar(1000)),1,1,'')) as PROV_NAMES