在存储过程中连接SQL语句的问题???
DECLARE @ExeSQL nvarchar(1000)
SET @ExeSQL = 'SELECT ROW_NUMBER() OVER(Order By CD.OutDate DESC) AS SerialNumber,C.Name,SB.ID,M.Member_Name,CD.OutDate FROM dbo.CertifiedDetail CD Inner Join dbo.Customers C On CD.CustomerID = C.ID Inner Join dbo.SaleBill SB On CD.SaleID = SB.ID Inner Join dbo.Member M On SB.MemberID = M.Member_ID WHERE CD.IsDelete = 0 And (CD.OutDate Between ' ' ' + @StartDate + ' ' ' And ' ' ' + @EndDate + ' ' ') '
print @ExeSQL
以上代码在运行存储过程时出现“从字符串向 datetime 转换时失败.”,@StartDate和@EndDate为存储过程参数
[解决办法]
你可以检查一下
@StartDate和@EndDate
传入的是否是有效的日期阿!
[解决办法]
(CD.OutDate Between ' ' ' + @StartDate + ' ' ' And ' ' ' + @EndDate + ' ' ') '
改为
(CD.OutDate Between @StartDate And @EndDate )
[解决办法]
恭喜!
[解决办法]
楼主牛啊