declare @P1 int
set @P1=NULL
exec proc_Search_CheckLog_All @id_card = '', @SearchKey = '', @KeyType = 1, @SearchType = 1, @PageSize = 10, @PageIndex = 1, @StartTime = '09 24 2005 12:00AM', @EndTime = '09 24 2008 12:00AM', @PageCount = @P1 output
select @P1
执行上述存储过程后报错。说:从字符串转换为 datetime 时发生语法错误。是存储过程里这行说我有错。
set @strsql = @strsql + ' and billdate between '+@StartTime+' and '+@EndTime+''请问是什么问题?

解决方案 »

  1.   

    @StartTime@EndTime 的值格式应该有问题
      

  2.   

    set @strsql = @strsql + ' and billdate between '''+@StartTime+''' and '''+@EndTime+'''' 试下
      

  3.   

    set @strsql = @strsql + ' and billdate between '+ cast(@StartTime as datetime)+' and '+cast(@EndTime as datetime)+'' 
      

  4.   

    set @strsql = @strsql + ' and billdate between '+cast(@StartTime as varchar)+' and '+cast(@EndTime as varchar)+'' 
      

  5.   

    我现在改成了set @strsql = @strsql + ' and billdate between '+Convert(varchar(32),@StartTime)+' and '+Convert(varchar(32),@EndTime)+''抱了另外一个错:过程需要参数 '@statement' 为 'ntext/nchar/nvarchar' 类型。我里面没有定义这个@statement
    不晓得是哪里出了问题了
      

  6.   

    同意三楼,直接用24小时计时制
    数据库中的DateTime就是24小时制的,试试看!
      

  7.   

    declare @P1 int
    set @P1=NULL
    exec proc_Search_CheckLog_All @id_card = '', @SearchKey = '', @KeyType = 1, @SearchType = 1, @PageSize = 10, @PageIndex = 1, @StartTime = cast('09 24 2005 12:00AM',datetime), @EndTime = cast('09 24 2008 12:00AM',datetime), @PageCount = @P1 output
    select @P1试试
      

  8.   


    set @strsql = @strsql + ' and billdate between '+dateadd(hh,12,cast(@StartTime as datetime))+' and '+dateadd(hh,12,cast(@EndTime as datetime))+''
      

  9.   

    09 24 2005 12:00AM
    在SQL中好像装换不了datetime
      

  10.   

    set @strsql = @strsql + ' and billdate between '''+cast(@StartTime as varchar)+''' and '''+cast(@EndTime as varchar)+''''