数据库为sql server 2000.
数据库表中某列名为dDate,类型为DateTime.想根据textbox输入的内容进行查找如果输入:2007-12-12 则sql为  select * from table where dDate = '2007-12-12'如果输入:>=2007-12-12 则sql为 select * from table where dDate >= '2007-12-12'如果输入:<=2007-12-12 and >=2007-11-13 则sql为 select * from table where dDate<='2007-12-12' and dDate>='2007-11-13'大家有没有什么好的办法?
求源码 感谢

解决方案 »

  1.   

        dim s as string
        dim tmp() as string
        dim sql as string    sql="select * from tb where ddate "
        tmp=split(text1,"=")
        if ubound(tm)=0 then
            s="='"& text1 &"'"
        else
            s=tmp(0) & "=" &"'" & tmp(1) &"'"
        end ff
        sql=sql & s
      

  2.   

    可以要求用户按下面的方式输入:日期<='2007-12-12' and 日期>='2007-11-13'
    然后程序中用下面方式合成:sql = "select * from table where " & replace(text1.text, "日期", "dDate")
      

  3.   

    我估计楼主这样设计要给客户骂,呵呵
    你何不用二个textbox来输入日期?
      

  4.   


        Dim s As String
        Dim tmp() As String
        
        s = Text1
        s = Replace(s, "=", "")
        s = Replace(s, ">", "")
        s = Replace(s, "<", "")
        tmp = Split(LCase(s), "and")
        If UBound(tmp) = 0 Then
            s = "='" & Text1 & "'"
        Else
            s = Replace(Text1, Trim(tmp(0)), "'" & Trim(tmp(0)) & "'")
            s = Replace(s, Trim(tmp(1)), "'" & Trim(tmp(1)) & "'")
        End If
        Debug.Print "select * from tb where edate " & s
      

  5.   


     Dim s As String
        Dim tmp() As String
        
        s = Text1
        s = Replace(s, "=", "")
        s = Replace(s, ">", "")
        s = Replace(s, "<", "")
        tmp = Split(LCase(s), "and")
        If UBound(tmp) = 0 Then
            s = "='" & Text1 & "'"
        Else
            s = Replace(Text1, Trim(tmp(0)), "'" & Trim(tmp(0)) & "'")
            s = Replace(s, Trim(tmp(1)), "'" & Trim(tmp(1)) & "'")
            s = Replace(s, "and", "and ddate")
        End If
        Debug.Print "select * from tb where ddate " & s
      

  6.   

    >= and <= 是没有问题了就是< 和 > 有问题结果是 And Djrq ='>2007-1-1'