我在写一个vb查询oracle程序时发现一个问题,就是单个执行select语句时都能通过,而使用union all时一直报错:
strdb="select .................. from table1 where .........." _
&" union all " _
&" select b ....................from table2 where ......"
一会儿说表达式不匹配,一会儿说select语句没有结束,请教各位该怎么改啊

解决方案 »

  1.   


    sql贴的不全怎么帮你改?
      

  2.   

    哦,不好意思,下面是原程序:
    Private Sub Command1_Click()Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    Set MSHFlexGrid1.DataSource = Nothingd1 = DTPicker1.Value
    d2 = DTPicker2.Value
    'MSHFlexGrid1.BackColor = RGB(230, 230, 230)cn.CursorLocation = adUseClient
    cn.Open "Provider=MSDAORA.1;Password=ic6279admin;User ID=ICADMIN;Data Source=ORAISSUE;Persist Security Info=True"If d1 > d2 Then
     MsgBox ("error 开始日期必须小于结束日期")
     Exit Sub
    Else
     strdb = "select name, id, card, balance, vailddate from usercard where updateto_date('" & Format(d1, "yyyy-mm-dd") & "','yyyy-mm-dd')" _
    & "union all " _
    & "select balance name, id, card, balance, vailddate from usercard where loddate=to_date('" & Format(d1, "yyyy-mm-dd") & "','yyyy-mm-dd')"
    End Ifrs.Open strdb, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
    Set MSHFlexGrid1.DataSource = rsrs.Close
    cn.Close
    End Sub
      

  3.   

    好像是少了空格的关系。    strdb = "select name,id,card,balance,vailddate from usercard where updateto_date('" & Format(d1, "yyyy-mm-dd") & "','yyyy-mm-dd')" _
                & " union all " _
                & "select balance name, id, card, balance, vailddate from usercard where loddate=to_date('" & Format(d1, "yyyy-mm-dd") & "','yyyy-mm-dd')"
      

  4.   

    strdb = "select name, id, card, balance, vailddate from usercard where update=to_date('" & Format(d1, "yyyy-mm-dd") & "','yyyy-mm-dd')" _ 
    & "union all " _ 
    & "select balance name, id, card, balance, vailddate from usercard where loddate=to_date('" & Format(d1, "yyyy-mm-dd") & "','yyyy-mm-dd')" 
      

  5.   

    strdb = "select name, id, card, balance, vailddate from usercard where update=to_date('" & Format(d1, "yyyy-mm-dd") & "','yyyy-mm-dd') " _ 
    & "union all " _ 
    & "select balance name, id, card, balance, vailddate from usercard where loddate=to_date('" & Format(d1, "yyyy-mm-dd") & "','yyyy-mm-dd')" 
      

  6.   

    Private Sub Command1_Click()
        Dim strdb As String    d1 = "2008-11-15"
           
        strdb = ""
        strdb = strdb & "select name, id, card, balance, vailddate " & vbNewLine
        strdb = strdb & "  from usercard " & vbNewLine
        strdb = strdb & " where update=to_date('" & Format(d1, "yyyy-mm-dd") & "','yyyy-mm-dd')" & vbNewLine
        strdb = strdb & "union all " & vbNewLine
        strdb = strdb & "select balance name, id, card, balance, vailddate  " & vbNewLine
        strdb = strdb & "  from usercard " & vbNewLine
        strdb = strdb & " where loddate=to_date('" & Format(d1, "yyyy-mm-dd") & "','yyyy-mm-dd')"
        
        Debug.Print strdbEnd Subselect name, id, card, balance, vailddate 
      from usercard 
     where update=to_date('2008-11-15','yyyy-mm-dd')
    union all 
    select balance name, id, card, balance, vailddate  
      from usercard 
     where loddate=to_date('2008-11-15','yyyy-mm-dd')