有问题的语句:
exec('insert into '+@ods_dbname+'.dbo.DictionaryLibrary select * from '+@linkname+'.'+@yuan_dbname+'.dbo.'+@tbname+'
where LastModifyDateTime
between dateadd(day,-1,'+@start_time+') and '+@start_time+'')
上面的一条语句是在存储过程里面的,编译是成功的,执行之后却没有数据有数据的语句:
insert into ODS_GZ.dbo.ODS_T_DictionaryLibrary select * from link_gz.[GZ_EOMP].[dbo].[DictionaryLibrary]
where LastModifyDateTime
between dateadd(day,-1,@start_time) and @start_time;我想问存储过程的怎么会没有数据出来呢?怎么改?
exec('insert into '+@ods_dbname+'.dbo.DictionaryLibrary select * from '+@linkname+'.'+@yuan_dbname+'.dbo.'+@tbname+'
where LastModifyDateTime
between dateadd(day,-1,'+@start_time+') and '+@start_time+'')
上面的一条语句是在存储过程里面的,编译是成功的,执行之后却没有数据有数据的语句:
insert into ODS_GZ.dbo.ODS_T_DictionaryLibrary select * from link_gz.[GZ_EOMP].[dbo].[DictionaryLibrary]
where LastModifyDateTime
between dateadd(day,-1,@start_time) and @start_time;我想问存储过程的怎么会没有数据出来呢?怎么改?
这样子print?
declare @Statment nvarchar(4000)
set @Statment ='delete from '+@ods_dbname+'.dbo.'+@tbname+' where LastModifyDateTime
between dateadd(day,-1,'+@start_time+') and '+@start_time+''
exec sp_executesql @Statment
print @Statment执行结果:
(0 行受影响)
delete from ods_gz.dbo.DictionaryLibrary where LastModifyDateTime
between dateadd(day,-1,2011-07-20) and 2011-07-20
看上面的print,我执行print的结果,delete from ods_gz.dbo.DictionaryLibrary where LastModifyDateTime
between dateadd(day,-1,2011-07-20) and 2011-07-20,居然没删除数据
between dateadd(day,-1,2011-07-20) and 2011-07-20
你自己看看,这个sql对吗
between dateadd(day,-1,2011-07-20) and 2011-07-20 时间不带个引号?
exec('insert into '+@ods_dbname+'.dbo.DictionaryLibrary select * from '+@linkname+'.'+@yuan_dbname+'.dbo.'+@tbname+'
where LastModifyDateTime
between dateadd(day,-1,'+''''+@start_time+''''+') and '+''''+@start_time+''''+'')/*然后拼接SQL建议如下写 好些*/
DECLARE @SQL VARCHAR(2000)
SET @SQL = '....'
EXEC(@SQL)