declare @fileName2 nvarchar(50)
declare @sql varchar(500)
--set @fileName2=convert(char(14),getdate(),12)+CONVERT(nvarchar,FLOOR(RAND()*10))
set @fileName2=convert(char(8),getdate(),112)+CONVERT(nvarchar,FLOOR(RAND()*10))
set @sql='bcp "select ''时间'',''班组'',''规格名称'' union all select testTime=CONVERT(varchar,testTime,121), userRole,specName from BRL_wfQuality_DB.dbo.historyDataList where userRole=''A'' " queryout d:\测厚数据'+@fileName2+'.xlsx -S"." -U"sa" -P"abc123" -c'
EXEC master..xp_cmdshell @sql
EXEC master..xp_cmdshell 'bcp "select ''时间'',''班组'',''规格名称'' union all select testTime=CONVERT(varchar,testTime,121), userRole,specName from BRL_wfQuality_DB.dbo.historyDataList where userRole=''A'' " queryout d:\@fileName.xlsx -S"." -U"sa" -P"abc123" -c'