日期参数的存储过程调用出错

影子传说_Hades 2013-03-06 11:30:39
刚刚开始搞,目前日期参数的存储过程调用出错,比如


CREATE PROCEDURE CountUserServDaysInMonth
@UserId int = null,
@ServiceId int = null,
@RORDate datetime = null
AS
BEGIN
PRINT 'RORDate is:'+CONVERT(datetime, @RORDate,101);
DECLARE @ServiceStartTimeRec datetime,@ServiceEndTimeRec datetime,@recNum int=0,@sumDays int=0;
SELECT @recNum = count(*) from UserServiceLog where UserId=@UserId and ServiceId=@ServiceId and @RORDate>= ServiceStartTime and @RORDate<= ServiceEndTime;
PRINT 'record num is:'+CONVERT(varchar, @recNum);
DECLARE cur_old_style CURSOR FOR select ServiceStartTime,ServiceEndTime from UserServiceLog where UserId=@UserId and ServiceId=@ServiceId and @RORDate>= ServiceStartTime and @RORDate<= ServiceEndTime;
OPEN cur_old_style
FETCH cur_old_style INTO @ServiceStartTimeRec,@ServiceEndTimeRec;
WHILE (@@fetch_status=0)
BEGIN
--根据类型来判断增加还是减少,但目前缺乏类型标识
DECLARE @i AS INT = 0;
select @i=DATEDIFF(day,@ServiceStartTimeRec,@ServiceEndTimeRec);
select @sumDays=@sumDays+@i;
FETCH cur_old_style INTO @ServiceStartTimeRec,@ServiceEndTimeRec;
END
CLOSE cur_old_style;
DEALLOCATE cur_old_style;
PRINT 'Days in this month is:'+CONVERT(varchar, @sumDays);
END


但是调用会报错

EXEC CountUserServDaysInMonth @UserId=56038925,@ServiceId=1,@RORDate='2010-06-30 23:59:59.0';


报错
[FreeTDS][SQL Server]Conversion failed when converting date and/or time from character string.
...全文
198 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
szm341 2013-03-06
  • 打赏
  • 举报
回复
PRINT 'RORDate is:'+CONVERT(datetime, @RORDate,101); -> PRINT 'RORDate is:'+CONVERT(varchar, @RORDate,101);
昵称被占用了 2013-03-06
  • 打赏
  • 举报
回复
FreeTDS是什么接口,找相关资料看看日期类型如何表示的 如果调用支持参数的,用参数传入,而不要拼接sql语句
影子传说_Hades 2013-03-06
  • 打赏
  • 举报
回复
EXEC CountUserServDaysInMonth @UserId=56038925,@ServiceId=1,@RORDate='2010-06-30 23:59:59'; 还是不行 [FreeTDS][SQL Server]Conversion failed when converting date and/or time from character string.
饮水需思源 2013-03-06
  • 打赏
  • 举报
回复
'2010-06-30 23:59:59'
昵称被占用了 2013-03-06
  • 打赏
  • 举报
回复
EXEC CountUserServDaysInMonth @UserId=56038925,@ServiceId=1,@RORDate='2010-06-30 23:59:59';

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧