Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.)
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.
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.
I agree with @Or
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?
I would say it really doesn't matter very much. It's a matter of personal preference. Mine is to have two variables.
OK, thanks!