sqlexact-onlineinvantive-controlinvantive-sql

SQL error in Invantive Control for Excel


This is for Invantive Control for Excel.

What could be causing an error at the second CREATE TABLE?

CREATE TABLE niveau1@inmemorystorage
AS
SELECT ID
,      Code
,      AddressLine1
,      Name
,      Parent
FROM   Accounts
WHERE  ID=$P{P_ACCOUNTID}

CREATE TABLE niveau2@inmemorystorage
AS
SELECT ID
,      Code
,      AddressLine1
,      Name
,      Parent
FROM   Accounts
WHERE  Parent IN (SELECT ID FROM niveau1@inmemorystorage)

CREATE TABLE niveau3@inmemorystorage
AS
SELECT ID
,      Code 
,      AddressLine1
,      Name
,      Parent
FROM   Accounts
WHERE  Parent IN (SELECT ID FROM niveau2@inmemorystorage)

SELECT * FROM niveau1@inmemorystorage
UNION ALL
SELECT * FROM niveau2@inmemorystorage
UNION ALL
SELECT * FROM niveau3@inmemorystorage

Solution

  • You have probably received an error: "The identifier 'Accounts' is ambiguous.". You can add the identifier where necessary.

    The working SQL for Exact Online accounts is shown below. Please note the use of create or replace table instead of create table, the privileges don't change (when there are any) but when necessary the table is dropped first.

    CREATE OR REPLACE TABLE niveau1@inmemorystorage
    AS
    SELECT act.ID
    ,      act.Code
    ,      act.AddressLine1
    ,      act.Name
    ,      act.Parent
    FROM   exactonlinerest..Accounts act
    
    
    CREATE OR REPLACE TABLE niveau2@inmemorystorage
    AS
    SELECT act.ID
    ,      act.Code
    ,      act.AddressLine1
    ,      act.Name
    ,      act.Parent
    FROM   exactonlinerest..Accounts act
    join   niveau1@inmemorystorage n1
    on     n1.id = act.Parent
    
    CREATE OR REPLACE TABLE niveau3@inmemorystorage
    AS
    SELECT act.ID
    ,      act.Code 
    ,      act.AddressLine1
    ,      act.Name
    ,      act.Parent
    FROM   exactonlinerest..Accounts act
    join   niveau2@inmemorystorage n2
    on     n2.id = act.Parent
    
    SELECT * FROM niveau1@inmemorystorage
    UNION ALL
    SELECT * FROM niveau2@inmemorystorage
    UNION ALL
    SELECT * FROM niveau3@inmemorystorage