这等效于HANA中SQL Server的SELECT * INTO吗?

时间:2019-07-04 03:19:15

标签: sql-server sap hana

我目前正在将我们公司的某些SQL代码转换为HANA,但我偶然发现了这堵墙。这是我的SQL示例代码:

SQL

select
    level1.acctcode as 'acctcode1', level1.acctname as 'acctname1',
    level1.fathernum as 'fathernum1', level1.FormatCode as 'formatcode1', 
    level1.Levels as Level1,
    level2.acctcode as 'acctcode2', level2.acctname as 'acctname2',
    level2.fathernum as 'fathernum2', level2.FormatCode as 'formatcode2', 
    level2.Levels as Level2,
    level3.acctcode as 'acctcode3', level3.acctname as 'acctname3',
    level3.fathernum as 'fathernum3', level3.FormatCode as 'formatcode3', 
    level3.Levels as Level3,
    level4.acctcode as 'acctcode4', level4.acctname as 'acctname4',
    level4.fathernum as 'fathernum4', level4.FormatCode as 'formatcode4', 
    level4.Levels as Level4,
    -- ..... and so on for several more groups of columns ......
    isnull(level10.GrpLine, isnull(level9.GrpLine, isnull(level8.GrpLine, isnull(level7.GrpLine, isnull(level6.GrpLine, isnull(level5.GrpLine, isnull(level4.GrpLine, isnull(level3.GrpLine, isnull(level2.GrpLine, level1.GrpLine))))))))) GrpLine,
    level1.groupmask
into
    #OACT
from 
    (select 
         AcctCode, AcctName, GroupMask, GrpLine, FatherNum, FormatCode, Levels 
     from 
         oact with(nolock) 
     where 
         levels = '1') level1 
left join
    (select 
         AcctCode, AcctName, GroupMask, GrpLine, FatherNum, FormatCode, Levels 
     from 
         oact with(nolock) 
     where 
         levels = '2') level2 on level2.fathernum = level1.acctcode
left join
    (select 
         AcctCode, AcctName, GroupMask, GrpLine, FatherNum, FormatCode, Levels 
     from 
         oact with(nolock) 
     where 
         levels = '3') level3 on level3.fathernum = level2.acctcode
--- ... and so on for level 4 through 10 .....

这是我对HANA的看法:

CREATE LOCAL TEMPORARY COLUMN TABLE #OACT AS (

        SELECT level1."acctcode" AS "acctcode1", level1."acctname" AS "acctname1", 
            level1."fathernum" AS "fathernum1", level1."FormatCode" AS "formatcode1", 
            level1."Levels" AS "Level1", level2."acctcode" AS "acctcode2", level2."acctname" AS "acctname2", 
            level2."fathernum" AS "fathernum2", level2."FormatCode" AS "formatcode2", 
            level2."Levels" AS "Level2", level3."acctcode" AS "acctcode3", level3."acctname" AS "acctname3", 
            level3."fathernum" AS "fathernum3", level3."FormatCode" AS "formatcode3", 
            level3."Levels" AS "Level3", level4."acctcode" AS "acctcode4", level4."acctname" AS "acctname4", 
            level4."fathernum" AS "fathernum4", level4."FormatCode" AS "formatcode4", 
            level4."Levels" AS "Level4", level5."acctcode" AS "acctcode5", level5."acctname" AS "acctname5", 
            level5."fathernum" AS "fathernum5", level5."FormatCode" AS "formatcode5", 
            level5."Levels" AS "Level5", level6."acctcode" AS "acctcode6", level6."acctname" AS "acctname6", 
            level6."fathernum" AS "fathernum6", level6."FormatCode" AS "formatcode6", 
            level6."Levels" AS "level6", level7."acctcode" AS "acctcode7", level7."acctname" AS "acctname7", 
            level7."fathernum" AS "fathernum7", level7."FormatCode" AS "formatcode7", 
            level7."Levels" AS "level7", level8."acctcode" AS "acctcode8", level8."acctname" AS "acctname8", 
            level8."fathernum" AS "fathernum8", level8."FormatCode" AS "formatcode8", 
            level8."Levels" AS "level8", level9."acctcode" AS "acctcode9", level9."acctname" AS "acctname9", 
            level9."fathernum" AS "fathernum9", level9."FormatCode" AS "formatcode9", 
            level9."Levels" AS "level9", level10."acctcode" AS "acctcode10", level10."acctname" AS "acctname10", 
            level10."fathernum" AS "fathernum10", level10."FormatCode" AS "formatcode10", 
            level10."Levels" AS "level10", 
            IFNULL(level10."GrpLine", IFNULL(level9."GrpLine", IFNULL(level8."GrpLine", IFNULL(level7."GrpLine", 
            IFNULL(level6."GrpLine", IFNULL(level5."GrpLine", IFNULL(level4."GrpLine", IFNULL(level3."GrpLine", 
            IFNULL(level2."GrpLine", level1."GrpLine"))))))))) AS "GrpLine", level1."groupmask" 

        FROM (

        SELECT "AcctCode", "AcctName", "GroupMask", "GrpLine", "FatherNum", "FormatCode", "Levels" 
            FROM OACT 
            WHERE "Levels" = '1') AS level1 
            LEFT OUTER JOIN (SELECT "AcctCode", "AcctName", "GroupMask", "GrpLine", "FatherNum", "FormatCode", 
                "Levels" 
            FROM OACT 
            WHERE "Levels" = '2') AS level2 ON level2."fathernum" = level1."acctcode" 
            LEFT OUTER JOIN (SELECT "AcctCode", "AcctName", "GroupMask", "GrpLine", "FatherNum", "FormatCode", 
                "Levels" 
            FROM OACT 
            WHERE "Levels" = '3') AS level3 ON level3."fathernum" = level2."acctcode" 
            LEFT OUTER JOIN (SELECT "AcctCode", "AcctName", "GroupMask", "GrpLine", "FatherNum", "FormatCode", 
                "Levels" 
            FROM OACT 
            WHERE "Levels" = '4') AS level4 ON level4."fathernum" = level3."acctcode" 
            LEFT OUTER JOIN (SELECT "AcctCode", "AcctName", "GroupMask", "GrpLine", "FatherNum", "FormatCode", 
                "Levels" 
            FROM OACT 
            WHERE "Levels" = '5') AS level5 ON level5."fathernum" = level4."acctcode" 
            LEFT OUTER JOIN (SELECT "AcctCode", "AcctName", "GroupMask", "GrpLine", "FatherNum", "FormatCode", 
                "Levels" 
            FROM OACT 
            WHERE "Levels" = '6') AS level6 ON level6."fathernum" = level5."acctcode" 
            LEFT OUTER JOIN (SELECT "AcctCode", "AcctName", "GroupMask", "GrpLine", "FatherNum", "FormatCode", 
                "Levels" 
            FROM OACT 
            WHERE "Levels" = '7') AS level7 ON level7."fathernum" = level6."acctcode" 
            LEFT OUTER JOIN (SELECT "AcctCode", "AcctName", "GroupMask", "GrpLine", "FatherNum", "FormatCode", 
                "Levels" 
            FROM OACT 
            WHERE "Levels" = '8') AS level8 ON level8."fathernum" = level7."acctcode" 
            LEFT OUTER JOIN (SELECT "AcctCode", "AcctName", "GroupMask", "GrpLine", "FatherNum", "FormatCode", 
                "Levels" 
            FROM OACT 
            WHERE "Levels" = '9') AS level9 ON level9."fathernum" = level8."acctcode" 
            LEFT OUTER JOIN (SELECT "AcctCode", "AcctName", "GroupMask", "GrpLine", "FatherNum", "FormatCode", 
                "Levels" 
            FROM OACT 
            WHERE "Levels" = '10') AS level10 ON level10."fathernum" = level9."acctcode");

问题是我遇到错误

  

无效的列名称:LEVEL2.fathernum:第56行第59行

我有一种直觉,即通过select语句创建临时表时,HANA不会像SQL Server那样自动化。

0 个答案:

没有答案