简体   繁体   English

在VBA中使用易失表进行TeraData查询

[英]TeraData query in VBA with volatile table

I'm trying to automate a sequence of queries. 我正在尝试自动执行一系列查询。 One query, say Q1, is problematic as it creates a volatile table prior to the select statement. 一个查询(例如Q1)是有问题的,因为它在select语句之前创建了一个易失表。 Within TeraData, Q1 runs fine but when passing Q1 to TeraData through VBA I get an error: 在TeraData中,Q1运行良好,但是当通过VBA将Q1传递给TeraData时,出现错误:

Only an ET or null statement is legal after a DDL Statement. DDL语句之后,只有ET或null语句是合法的。

Q1 is of the form: Q1的形式为:

    create multiset volatile table volatileTable,
    no fallback,
    no before journal,
    no after journal,
    (
        a1,
        a2,
        a3,
        a4,
        a5
    ) as 
    (sel
        b1,
        b2,
        b3,
        min(b4) as a1,
        min(b5) as a2
    from
        db.table
    where
        b6 = 'condition'
    group by
        b1,
        b2,
        b3
    )
    with data
    on commit preserve rows;

    sel
        c1,
        c2,
        c3
    from 
        db.table
    group by
        1,
        2

    union

    sel
        d1,
        d2,
        d3
    from 
        (sel
            e.f1,
            e.f2,
            e.f3,
            e.a1,
            s.a1,
            e.a2,
            s.a2,
            e.a3,
            s.a3,
            e.a4,
            s.a4,
            e.a5,
            s.a5
        from 
            db.table) as e
            left outer join volatileTable as s
            on
                e.a1 = s.a1
                e.a2 = s.a2
                e.a3 = s.a3
                e.a4 >= s.a4
                e.a5 <= s.a5    
    group by
        1,
        2

    union

    sel
        g1,
        g2,
        g3
    from 
        db.table
    group by
        1,
        2

    union

    ...

The problem has got to be with creating a volatile table within the VBA ADODB.Command.Execute() statement. 问题必须与在VBA ADODB.Command.Execute()语句中创建易失表有关。 Any ideas on how to get around this? 关于如何解决这个问题的任何想法?

You are connectected in BT/ET mode. 您已在BT / ET模式下连接。 After executing the Q1 query, execute "ET" command to end the transaction. 执行完Q1查询后,执行“ ET”命令以结束事务。

Or you could connect in Teradata default mode to do auto commit of queries. 或者,您可以在Teradata默认模式下连接以自动提交查询。

You must send the Create and the Select in two separate requests. 您必须在两个单独的请求中发送“创建”和“选择”。

In an ANSI session you must add a COMMIT; 在ANSI会话中,您必须添加COMMIT。 to the Create after on commit preserve rows; 提交后创建提交保留行;

To switch to from an ANSI to a Teradata session you need to change to Session Mode=Teradata; 要从ANSI会话切换到Teradata会话,您需要更改为Session Mode = Teradata;

If you're in a Teradata mode session, there's no need for BT/ET as every request is an implicit transaction. 如果您处于Teradata模式会话中,则无需BT / ET,因为每个请求都是隐式事务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM