0

你好,我是 SAP HANA 的新手,我有这个 T-SQL 代码:

`if(@IsBes='E')begin

               if((select top 1 U_bBesYontem from OHEM where empID=@EmpId)='O') begin

                     set @Bes=@Brut*(select top 1 U_bBesOran from OHEM where empID=@EmpId)/100

                  end

               if((select top 1 U_bBesYontem from OHEM where empID=@EmpId)='T') begin

                     set @Bes=(select top 1 U_bBesTutar from OHEM where empID=@EmpId)

                  end

         end`

我正在为 SAP HANA 尝试这段代码

IF (:IsBes = 'E') THEN IF ((SELECT TOP 1 “U_bBesYontem" FROM OHEM WHERE "empID" = :EmpId) = 'O') THEN Bes := :Brut * (SELECT TOP 1 "U_bBesOran" FROM OHEM WHERE "empID" = :EmpId) / 100; END IF; IF ((SELECT TOP 1 "U_bBesYontem" FROM OHEM WHERE "empID" = :EmpId) = 'T') THEN SELECT (SELECT TOP 1 "U_bBesTutar" FROM OHEM WHERE "empID" = :EmpId) INTO Bes FROM DUMMY; END IF; END IF;

并尝试了很多代码变体,但我总是最终得到这个错误:

SAP DBTech JDBC: [7]: feature not supported:
 Sub-query is not supported in a nested procedure call: 
 line 47 col 28 (at pos 2273)

我很困惑,所以有人可以提供任何建议吗?

4

1 回答 1

1

梅哈巴,

您能否在测试数据库上执行以下 SQLScript

do
begin

declare lv_EmpId int := 1;
declare lv_IsBes char(1) := 'E';
declare lv_Bes decimal(10,2); 
declare lv_Brut decimal(10,2) := 100;
declare lv_U_bBesYontem nvarchar(100);
declare lv_U_bBesOran int;
declare lv_U_bBesTutar int;

select top 1 
    U_bBesYontem, U_bBesOran, U_bBesTutar
into 
    "LV_U_BBESYONTEM", "LV_U_BBESORAN", "LV_U_BBESTUTAR"
from OHEM where EmpId = lv_EmpId;

if (:lv_IsBes = 'E') then

    if(:lv_U_bBesYontem = 'O') then
        lv_Bes = ( :lv_Brut * :lv_U_bBesOran ) /100;
    else
        if (:lv_U_bBesYontem = 'T') then
            lv_Bes = :lv_U_bBesTutar;
        end if;
    end if;

end if;

select :lv_Bes as "BES" from dummy;

end;

我使用了以下示例数据,它似乎工作得很好,请根据您的表和字段名称等修改脚本。

CREATE Column TABLE OHEM (
    empID int,
    U_bBesYontem varchar(10),
    U_bBesOran int,
    U_bBesTutar int
);
insert into OHEM select 1, 'O',5,1000 from dummy;
insert into OHEM select 2, 'O',10,500 from dummy;
insert into OHEM select 1, 'T',5,1000 from dummy;
insert into OHEM select 2, 'T',10,500 from dummy;

您可以在给定的示例文档中参考 SQLScript上的变量声明、赋值、IF 子句等。

于 2018-04-04T10:53:07.050 回答