SQL, Layout for CSV



我希望在那里制作i.ItemLookupCode, t.tostoreid, t.fromponumber, t.toloc_itemdescription, t.qtydifference自己的列。目前,当我运行脚本时,数据都在一列中。

请参阅下面的当前脚本。

EXEC msdb. dbo .sp_send_dbmail @recipients= 'ME@ME.com' ,
@profile_name = 'mymailprofile' ,
@subject ='Quantity difference ' ,
@body ='Quantity difference ' ,
@query = '
(
  select i.ItemLookupCode, t.tostoreid, t.fromponumber, t.toloc_itemdescription, t.qtydifference
  from
  [RAMPApple] .[dbo]. [RAPurchaseOrderTransfer] t
  inner join [RAMPApple] .[dbo]. [RAItems] i on t.TOLOC_ItemDescription = i.ItemDescription
   where QtyDifference <> 0 and fromstoreid = 111 and t.DateCreated >= dateadd(dd, -30,  GETDATE()))
' ,
@query_result_header = 1,
@attach_query_result_as_file = 1 ,
@query_attachment_filename = 'Quantity_difference.csv' ,
@query_result_separator = '     ' ,
@query_result_no_padding = 1

如果你试图构建一个CSV,那么在我看来,你需要分隔符是逗号,对吧?目前,您正在使用某种空白作为分隔符,因此整行看起来是一列。

尝试使用:

@query_result_separator = ',' ,

而不是

@query_result_separator = '     ' ,

最新更新