Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
BartVA
Creator
Creator

Best practice: dates as integers versus SQL where clause problems

I read The Date Function - Qlik Community - 1463157 and Why don’t my dates work? - Qlik Community - 1465849 and in the last, the author writes "My recommendation is to always use numeric variables for dates."

Seems sound advice to me.

So I made a variable as follows:

LET vGeneralStartDate = Num(Date#('20230101', 'YYYYMMDD'));

//Resolves to 44569

At the same time, I need to load tables from PostGreSQL with dates in the format 'DD/MM/YYYY', only after vGeneralStartDate. What would best practice be to solve the difference in format between my numeric (integer) variable, and the PostGreSQL data in 'DD/MM/YYYY' format.

For instance in the code below:

LET vGeneralStartDate = Num(Date#('20230101', 'YYYYMMDD'));

Let vTableName = 'res_currency_rate';

$(vTableName):
Load *
;
SQL SELECT *
FROM $(vTableName)
WHERE name >= vGeneralStartDate
ORDER BY name ASC;

(The following works, but doesn't seem elegant to me:

LET vGeneralStartDateSQL = Date(Date($(vGeneralStartDate)), 'YYYYMMDD');

and then use vGeneralStartDateSQL in the where clause.)

Labels (2)
1 Solution

Accepted Solutions
Or
MVP
MVP

I think what hic was after in that post was that you should use numerics for your Qlik code. For variables that are being passed to an SQL query, you still need to use whatever the database being queried will accept, which may not be a numeric value.

View solution in original post

5 Replies
Or
MVP
MVP

I think what hic was after in that post was that you should use numerics for your Qlik code. For variables that are being passed to an SQL query, you still need to use whatever the database being queried will accept, which may not be a numeric value.

theoat
Partner - Specialist
Partner - Specialist

I agree with @Or 

BartVA
Creator
Creator
Author

What would be the best way to do so with a variable that you need in various places (both in SQL select statements where it needs to be non-numeric, and in other places in Qlik where it may be preferrable to use integers)? Make a second variable, as I did, in the right format for the SQL? Or "on the fly" in the SELECT statement of the Load? Or still something else?

Or
MVP
MVP

I would say it really doesn't matter very much. It's a matter of personal preference. Mine is to have two variables.

BartVA
Creator
Creator
Author

OK, thanks!