数据库使用的是SQL2005,有字段BeginDate(开始日期)和EndDate(结束日期),现在想按照这两个来查询数据附件不知道能看到图吗,可以选择开始日期和结束日期,也可以为空

解决方案 »

  1.   

    sql="  ....  where 1=1 "
    如果 开始时间不为空
        Sql+=" and 时间>'BeginDate' "如果 结束时间不为空
         Sql+=" and 时间<EndDate "
      

  2.   

    string str = strDate.text
    string end = endDate.textDB
    if(!string.isnullorempty(str))
    {
      sql += "and strDate > str"
    }
    领会精神
      

  3.   

    Create_Date<= @EndDate AND Create_Date> @StartDate
      

  4.   


    set   nocount   on
    declare   @s   nvarchar(4000)
    select   @s='Select * from table1 where 1=1'
     +case   when   @StartDateFrom>''   then   '   and   datediff(d,StartDate,@StartDateFrom)<=0 '   else   ''   end 
     +case   when   @StartDateTo>''   then   '   and   datediff(d,StartDate,@StartDateTo)>=0 '   else   ''   end 
    exec   sp_executesql   @s,   
      N'@StartDateFrom   varchar(10)=null,
      @StartDateTo   varchar(10)'
    @StartDateFrom,@StartDateTo