语句1:Select * from where opendate = '2010-03-29'
正确的代码  能根据时间得到结果
语句2:Select * from where opendate = 2010-03-29
错误的代码 解释器不报错 但是得不到结果我用。net生成语句
用什么方法才能生成语句1那样子的语句?

解决方案 »

  1.   

    这是Asp的,生成SQL时就加上变量:
    Dim strSql
    strSql="select * from where opendate='"&Date&"'"
      

  2.   

    Select * from where opendate = 2010-03-29 2010-03-29当成减法了SELECT DATEADD(DD, 2010-03-29,0)
      

  3.   

    。2010-03-29 不加引号就是普通的减法
     dateadd(day,2010-03-29,0)
      

  4.   


    string strCondition = "openDate = '" + _date.ToShortDateString()+"'"我的查询条件是这样子生成的
    把这个生成的语句放进去执行就没有结果了
      

  5.   


    @condition = N'beginDate = ''2010-03-25'''执行存储过程的时候  传进去的值是这样子的  但是解释器报错了  说''有错误  如果不加引号进去后就变成语句2的情况,加了引号又出错  怎么办?
      

  6.   

    @condition = N'beginDate = '''2010-03-25''''
    引号要进行转义 ,转义符是'