sqlserver从字符串向datetime转换时失败
declare @StartDate datetime, @EndDate dateTime select @tsql = @tsql + ' and a.UP_Time between ' + @StartDate + ' and ' + @EndDate
上述是时间比较的问题。编译没报错,执行就报错“从字符串向datetime转换时失败”
' and a.UP_Time between ' + 字符串
@EndDate @StartDate datetime 类型
DECLARE @tsql NVARCHAR(max) SET @tsql='' declare @StartDate DATETIME='2013-04-26 00:00:01', @EndDate dateTime ='2013-04-26 15:00:01' --PRINT CONVERT(VARCHAR(30),@StartDate,120) --PRINT CONVERT(VARCHAR(30),@EndDate,120) SELECT @tsql =@tsql+ ' and a.UP_Time between ' +''''+CONVERT(VARCHAR(30),@StartDate,120)+'''' +' and ' +''''+CONVERT(VARCHAR(30),@EndDate,120)+''''print @tsql