100分求大家来看看这个问题啊!!
我写了个存储过程,如下:
CREATE PROCEDURE IOIOT_bbsTopic_DeleteByDate
(
@startDate varchar(255),
@endDate varchar(255)
)
AS
BEGIN
declare @strsql nvarchar(255)
IF @startDate <> ' ' and @endDate <> ' '
SET @strsql = 'DELETE FROM [table1] WHERE topDate BETWEEN '+ Convert(datetime,@startDate,120) + ' and '+Convert(datetime,@endDate,120)
EXEC (@strsql)
END
GO
可是每当我执行的时候:
exec IOIOT_bbsTopic_DeleteByDateAndFunction '2007-02-02 ', '2007-02-06 '
就报这个错:从字符串转换为 datetime 时发生语法错误。
这是怎么解决啊,谢谢大家来指教一下!!!
------解决方案--------------------CREATE PROCEDURE IOIOT_bbsTopic_DeleteByDate
(
@startDate varchar(255),
@endDate varchar(255)
)
AS
BEGIN
declare @strsql nvarchar(255)
IF @startDate <> ' ' and @endDate <> ' '
SET @strsql = 'DELETE FROM [table1] WHERE topDate BETWEEN ' ' '+@startDate + ' ' ' and ' ' '+@endDate + ' ' ' '
EXEC (@strsql)
END
GO
------解决方案--------------------晕,慢了一步