从字符串转换为 datetime 时发生语法错误。
Create procedure [dbo].[SP_RF_SaveTransTime]
@sCaller varchar(24),
@ID int,
@inputetime varchar(10)
as
begin
declare @tempTime datetime
declare @sMonth varchar(2)
declare @sDay varchar(2)
declare @sHour varchar(2)
declare @sMinute varchar(2)
set @tempTime=rtrim(cast (@inputetime as datetime))
update t_rf_userfolder
set fTransferTime=@tempTime
where fCaller=@sCaller and fTaskID=@ID
select
@sMonth = cast(datepart(month,fTransferTime) as varchar(2)),
@sDay = cast(datepart(Day,fTransferTime) as varchar(2)),
@sHour = cast(datepart(Hour,fTransferTime) as varchar(2)),
@sMinute = cast(datepart(Minute,fTransferTime) as varchar(2))
from t_rf_userfolder
where fCaller=@sCaller and fTaskID=@ID
if(@@error = 0 and @@rowcount = 1)
begin
select @sMonth,@sDay,@sHour,@sMinute
end
end
GO
运行后提示从字符串转换为 datetime 时发生语法错误。
这个得怎么改?
[解决办法]
--注意 @inputetime 传入参数的格式,另外,建议修改一句语句为如下:
set @tempTime=cast(@inputetime as datetime)
[解决办法]
用 ISDATE() 函数判断一下,如果为1则为合法格式。
[解决办法]
20070828可以直接转换成日期类型
declare @inputtime varchar(8)
set @inputtime = '20070828 '
print cast (@date as datetime)