Alguien me ayuda por favor con este código que estoy convirtiendo a Hana desde Sql Server
CREATE FUNCTION "getDocNum_Pedidos"
(
dockey INT,
doctype INT,
valrettipo INT
)
RETURNS TABLE ListPed varchar(250)
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
BEGIN
If (valrettipo = 1) THEN
BEGIN
IF (doctype = 15) THEN
ListPed = (SELECT STRING_AGG(ListPed, ',') || Rtrim(lTrim(TO_VARCHAR(ORDR."DocNum"))) from ORDR Where "DocEntry" IN (SELECT "BaseEntry" From DLN1 Where "DocEntry" = dockey and "BaseType"= 17 Group by "BaseEntry") Group by "DocNum");
ELSEIF (doctype = 17) THEN
ListPed = (SELECT STRING_AGG(ListPed, ',') || Rtrim(LTrim(TO_VARCHAR(ORDR."DocNum"))) From ORDR Where "DocEntry" IN (Select "BaseEntry" From INV1 Where "DocEntry" = dockey and "BaseType"= 17 Group by "BaseEntry") Group by "DocNum");
END IF;
END;
ELSEIF (valrettipo = 2) THEN
BEGIN
IF (doctype = 15) THEN
ListPed = (SELECT TOP 1 OUSR."U_NAME" FROM ORDR JOIN OUSR ON ORDR."UserSign" = OUSR."USERID"
WHERE "DocEntry" IN (Select "BaseEntry" FROM DLN1 WHERE "DocEntry" = dockey AND "BaseType"=17 GROUP BY "BaseEntry"));
ELSEIF (doctype = 17) THEN
ListPed = (SELECT TOP 1 OUSR."U_NAME" FROM ORDR join OUSR on ORDR."UserSign"=OUSR."USERID"
WHERE "DocEntry" IN (Select "BaseEntry" From INV1 Where "DocEntry" = dockey and "BaseType" = 17 Group by "BaseEntry"));
END IF;
END;
ELSEIF (valrettipo=3) THEN
BEGIN
IF (doctype = 15) THEN
ListPed = (SELECT Top 1 lTrim(Rtrim(TO_VARCHAR(ORDR."SlpCode"))) + ': ' + OSLP."SlpName" from ORDR join OSLP on ORDR."SlpCode"=OSLP."SlpCode"
Where "DocEntry" in (Select "BaseEntry" From DLN1 Where "DocEntry" = dockey and "BaseType" = 17 Group by "BaseEntry"));
ELSEIF doctype = 17 THEN
ListPed = (SELECT Top 1 lTrim(Rtrim(TO_VARCHAR(ORDR."SlpCode"))) + ': ' + OSLP."SlpName" From ORDR join OSLP on ORDR."SlpCode"= OSLP."SlpCode"
Where "DocEntry" IN (Select "BaseEntry" From INV1 Where "DocEntry" = dockey and "BaseType"= 17 Group by "BaseEntry"));
END IF;
END;
ELSEIF (valrettipo = 4) THEN
BEGIN
IF (doctype = 0) THEN
ListPed = (Select Coalesce(ListPed+',','')+NNM1."SeriesName"+'-'+ TO_VARCHAR("FolioNum") From OINV Join NNM1 On OINV."Series"=NNM1."Series"
Where "DocEntry" in (Select "DocEntry" From RCT2 Where "DocNum" = dockey));
ELSEIf (doctype = 1) THEN
ListPed = (Select MAX(T0."SlpCode") From OINV T0
Where T0."DocEntry" in (Select "DocEntry" from RCT2 Where "DocNum"=dockey));
END IF;
END;
Return ListPed;
END IF;
END