Excel VBA ADO SQL - Syntax error in From clause

前端 未结 1 1102
借酒劲吻你
借酒劲吻你 2021-01-16 06:43

The following SQL in VBA ADO gives the \'syntax error in From clause\' error.

Sub RunSQL2()

    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
            


        
相关标签:
1条回答
  • 2021-01-16 07:35

    Consider using a correlated count aggregate query for row number in place of the window function as this subquery should by compliant in Jet/ACE SQL:

    SELECT v.child_index, v.child_level, v.parent_level, u.child_index, v.parent_index 
    FROM
      (SELECT s.* 
       FROM  
         (SELECT t.*, (SELECT count(*) FROM [mydata$A1:C30020] sub 
                       WHERE sub.child_index <= t.child_index
                       AND sub.child_level = t.child_level) as [rownum] 
          FROM [mydata$A1:C30020] t
         ) s  
       WHERE [rownum] = 1
      ) u  
    INNER JOIN 
      (SELECT t2.*, 1 as [rownum] 
       FROM [mydata$A1:C30020] t2
      ) v  
    ON (v.parent_level = u.child_level) AND (v.[rownum] = u.[rownum])  
    
    UNION 
    
    SELECT w.child_index, w.child_level, w.parent_level, w.child_index, w.parent_index 
    FROM [mydata$A1:C30020] w  
    WHERE w.child_index = 1  
    ORDER BY v.child_index;
    
    0 讨论(0)
提交回复
热议问题