存储过程,提示“从字符串转换为 datetime 时发生语法错误”
哪位朋友帮忙看一下,谢咯!实在是不知道怎么弄了
alter proc [FS_SignIn_Batch]
@startime datetime ,
@endtime datetime
as
declare @start datetime
declare @end datetime
set @start=convert(varchar(100), @startime, 23)
set @end=convert(varchar(100), @endtime, 23)
declare @num int
declare @datediff int
select @datediff=datediff(day,@start,@end)
set @num=0
declare @uid int
declare Batch_Cur cursor
for select ID from FS_P_Login
open Batch_Cur
fetch from Batch_Cur into @uid
while @@FETCH_STATUS=0
begin
while @num<@datediff
begin
insert into FS_SignIn values(@uid,'','','','',dateadd(day,@num,'convert(varchar(100),getdate(),23)'))
set @num=@num+1
end
fetch next from Batch_Cur into @uid
end
close Batch_Cur
deallocate Batch_Cur
exec FS_SignIn_Batch @startime='2013-7-17',@endtime='2013-7-31'
错误信息:消息 241,级别 16,状态 1,过程 FS_SignIn_Batch,第 23 行
从字符串向 datetime 转换时失败。
------解决方案--------------------'convert(varchar(100),getdate(),23)' 这里出错。这句输出的是字符串,不能用在dateadd里。
------解决方案--------------------
ALTER PROC [FS_SignIn_Batch]
@startime DATETIME ,
@endtime DATETIME
AS
DECLARE @start DATETIME
DECLARE @end DATETIME
SET @start = @startime
SET @end = @endtime
DECLARE @num INT
DECLARE @datediff INT
SELECT @datediff = DATEDIFF(day, @start, @end)
SET @num = 0