请高手帮忙解决?
以下的SQL语句执行总是有错:
declare @sql varchar(130)
declare @ADate DATETIME
set @ADate = CONVERT(VARCHAR(10),GETDATE()-4,120)
set @sql = 'bcp "EXECUTE eHReOAData.dbo.eHR_MJDataDailyReport_V2 ADate " queryout D:\MJ_DailyData\ '+CONVERT(VARCHAR(10),getdate()-4,112)+ '.txt -c -S172.21.128.110 -Usa -P '
EXEC master..xp_cmdshell @sql
提示以下错误:
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type nvarchar to datetime.
可是以下的SQL却是可以执行的:
declare @ADate DATETIME
set @ADate = CONVERT(VARCHAR(10),GETDATE()-4,120)
EXECUTE eHReOAData.dbo.eHR_MJDataDailyReport_V2 @ADate
------解决方案--------------------declare @sql varchar(130)
declare @ADate varchar(20)
set @ADate = CONVERT(VARCHAR(10),GETDATE()-4,120)
set @sql = 'bcp "EXECUTE eHReOAData.dbo.eHR_MJDataDailyReport_V2 ' ' '+@ADate+ ' ' ' " queryout D:\MJ_DailyData\ '+CONVERT(VARCHAR(10),getdate()-4,112)+ '.txt -c -S172.21.128.110 -Usa -P '
EXEC master..xp_cmdshell @sql