1. 程式人生 > >mssql2008 列轉行語句

mssql2008 列轉行語句

select JOB_ORDER_ID,
  [CONTAINER_NO]=stuff((select ','+CONTAINER_NO+':{櫃型:'
  +(select ctn_type from SB_CTNDEF where DEF_NO = CONTAINER_SIZE_TYPE)+',體積:'+cast(GROSS_CUBE as varchar)+',重量:'+
  cast(GROSS_WEIGHT as varchar)+'}' from OZ_BK_CONTAINER  
  where JOB_ORDER_ID=a.JOB_ORDER_ID  for xml path('')),1,1,'')
from OZ_BK_CONTAINER a  where job_order_id = a.JOB_ORDER_ID  group by JOB_ORDER_ID






select  USR_CODE , USR_NAME from SB_USER 


select top 1
  [USR_CODE]=stuff((select USR_CODE from SB_USER  for xml path('')),1,1,'')
from SB_USER a