Skip to Content
0
Former Member
Feb 19, 2016 at 12:34 PM

Problem with converting SQL query to HANA

436 Views

Hi experts,

I'm new to SAP HANA database. I have to convert some MS SQL queries to HANA and I could convert all the basic queries except one. This query has lot of SQL functions used and I don't know what are the functions I can use instead in HANA. I tried to use the provided SAP HANA - SQL converter but it didn't give me working query as an output. Below you can see the original SQL query and the output of the converter(which is wrong). Can some one help me to convert this query? I'm just an intern 😀

ORIGINAL SQL QUERY :

SELECT T0.[BirthDate], T0.[CardCode], T1.[CardName], T0.[Name], T0.[Tel1], T0.[E_MailL] FROM OCPR T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode WHERE 1 = (FLOOR(DATEDIFF(dd,T0.[BirthDate],GETDATE()+" + period + ") / 365.25)) - (FLOOR(DATEDIFF(dd,T0.[BirthDate],GETDATE()-" + period + ") / 365.25))

here "period" is an integer value.

HANA QUERY GOT FROM CONVERTER :

SELECT T0."BirthDate", T0."CardCode", T1."CardName", T0."Name", T0."Tel1", T0."E_MailL" FROM OCPR T0 INNER JOIN OCRD T1 ON T0."CardCode" = T1."CardCode" WHERE 1 = (FLOOR(DAYS_BETWEEN(T0."BirthDate", ADD_DAYS('1900-01-01 00:00:00.000', NOW() + " + period + ")) / 365.25)) - (FLOOR(DAYS_BETWEEN(T0."BirthDate", ADD_DAYS('1900-01-01 00:00:00.000', NOW() - " + period + ")) / 365.25));

ERROR:

invalid name of function or procedure: DATEDIFF