我正在尝试查找一些与几个变量匹配的记录,它们是日期。
但是我收到了这个错误: 将字符串转换为smalldatetime数据类型
时转换失败从我的sql脚本。
ALTER PROCEDURE GetByTravelDates
(
@date_start as varchar,
@date_end as varchar
)
AS
select * from holiday_a hr
inner join holiday_b hw on
hr.holiday_id=hw.id
where date_start=CONVERT(SMALLDATETIME,@date_start,101) and date_end=CONVERT(SMALLDATETIME,@date_end,101)
然后从c#控件发布到SP:
string date = "24 Jan 2014";
string date2 = "29 Jan 2014";
数据库中的格式如下: 2014-01-24 00:00:00
YYYY-MM-DD
由于
答案 0 :(得分:2)
将varchar的大小定义为:
ALTER PROCEDURE GetByTravelDates
(
@date_start as varchar(15),
@date_end as varchar(15)
)
如果存在错误,请检查date_start.
答案 1 :(得分:1)
从
更改SP参数ALTER PROCEDURE GetByTravelDates
(
@date_start as varchar,
@date_end as varchar
)
AS
到
ALTER PROCEDURE GetByTravelDates
(
@date_start as varchar(15),
@date_end as varchar(15)
)
AS