sharesmlt..msgtjmy where lxtime>='''+ @stime+''' and lxtime< '''+ @nstime +''' )'================>
sharesmlt..msgtjmy where lxtime>='''+ convert(varchar,@stime)+''' and lxtime< '''+ convert(varchar,@nstime) +''' )'
sharesmlt..msgtjmy where lxtime>='''+ convert(varchar,@stime)+''' and lxtime< '''+ convert(varchar,@nstime) +''' )'
and fmsgtype=60 and fdestaddr not in(select mobile from
sharesmlt..msgtjmy where lxtime>='''+ @stime+''' and lxtime< '''+ @nstime +''' )'
exec (@sql)这句里面的@stime和@nstime都需要转换成字符格式,你没有转换。 convert(varchar(8),@stime,112)
declare @stime datetime,@nstime datetime,@count int
select @stime='2005-10-1 0:00:00'
select @nstime=dateadd(day,1,@stime)select @table='msgtable'+convert(varchar(8),@stime,112)
while(@table<'msgtable20051101')
begin
declare @sql varchar(3000)
select @sql='
insert sharesmlt..msgtjmy
select fdestaddr,fserviceID,fud,fsubmittime from '+ @table +' where fserviceID =''-YLTJMY''
and fmsgtype=60 and fdestaddr not in(select mobile from
--这里转换一下变量类型sharesmlt..msgtjmy where lxtime>='''
+ convert(varchar(10),@stime,102) --可以是你想要的数据类型
+''' and lxtime< '''
+ convert(varchar(10),@nstime,102) --这里也是
+''' )'
exec (@sql)
select @stime=dateadd(day,1,@stime)
select @table='msgtable'+convert(varchar(8),@stime,112)
end
还有这里要加intoinsert into sharesmlt..msgtjmy
select fdestaddr,fserviceID,fud,fsubmittime from '+ @table +' where fserviceID =''-YLTJMY''
and fmsgtype=60 and fdestaddr not in(select mobile from
select @sql='
insert sharesmlt..msgtjmy
select fdestaddr,fserviceID,fud,fsubmittime from '+ @table +' where fserviceID =''-YLTJMY''
and fmsgtype=60 and fdestaddr not in(select mobile from
sharesmlt..msgtjmy where convert(varchar,lxtime,112)>='''+ convert(varchar,@stime,112)+''' and convert(varchar,lxtime,112)< '''+ convert(varchar,@nstime,112) +''' )'
--同时请楼主检查一下,逻辑上似乎也有问题的。先不要执行,print出来看看。