DECLARE @fileName VARCHAR(100)='dzw.txt' DECLARE @cmd VARCHAR(100) DECLARE @path VARCHAR(200) --文件名 --E:\SendEmailSys\SSIS\doc SET @path = 'D:\PPReport\To_KEAS_GDC_ASN\' SET @cmd='mkdir '+ @path EXEC master..xp_cmdshell @cmd, NO_OUTPUT DECLARE @sql VARCHAR(8000),@u VARCHAR(200) SET @sql = 'SELECT s.ControlNo+ ''|'' + s.ShippedPN+ ''|'' + s.ShippedPN+ ''|'' + s.PPID+ ''|'' + s.Returnto+ ''|'' + Convert(varchar(50),s.TPRShippedDate,120)+ ''|'' + a.[RTV Number]' + ' FROM DBA.dbo.TABLE01(NOLOCK) s' + ' INNER JOIN DBA.dbo.TABLE02(NOLOCK) a ON s.ControlNo = a.ControlNo' SET @u = '" -T -t"," -c' SET @sql = 'BCP "'+ @sql +'" queryout "'+ @path + @fileName + @u EXEC master..xp_cmdshell @sql
标签:SET,VARCHAR,表格,ControlNo,SqlServer,sql,path,txt,DECLARE From: https://www.cnblogs.com/dzw159/p/16788507.html