cancel
Showing results for 
Search instead for 
Did you mean: 

Convert query to Hana

0 Kudos
513

Hey,

Could someone help me convert this query SQL Server for Hana?

Regards,

César

DECLARE @startano INT = 2018, @endano INT, @ano INT = YEAR(GETDATE()), @lote VARCHAR(3)
SET @endano = @startano + 25;


WITH BaseLote AS (SELECT @startano AS num1, 0 AS num2
                  UNION ALL
                  SELECT num1 + 1, num2 + 1 FROM BaseLote WHERE num1 + 1 <= @endano)
                  
SELECT @lote = ('L' + CHAR(num2 + 65) + '%') FROM BaseLote WHERE num1 = @ano


SELECT CASE WHEN MAX(DistNumber) IS NULL THEN 
LEFT(@lote,2) + '000000001'
            ELSE LEFT(MAX(DistNumber),2) + RIGHT('00000000'+ CONVERT(VARCHAR(12), 
            RIGHT(MAX(DistNumber), 9) + 1), 9) END
FROM OBTN
WHERE DistNumber LIKE @lote AND LEN(DistNumber) = '11'qu
View Entire Topic
fdvicente
Advisor
Advisor
0 Kudos

Hi César,

You can check the document below for guidelines on converting T-SQL to HANA SQL:

https://www.dngsystems.com/wp-content/uploads/2018/11/How_to_Convert_SQL_from_MS_SQL_Server_to_SAP_H...

Also, the SQL Converter Tool is available here:

https://developers.sap.com/trials-downloads.html?rid=%2Fwebcontent%2Fuuid%2Fd0f0686d-6e74-3010-ecac-...

Best Regards,

Filipe Vicente