Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
bharath28
Creator
Creator

convert date format to period

  Hi All,

Here is my existing query which i run in qlikview script, to fetch data from oracle-

load *;

select * from transactionTbl       

WHERE

            DATE >= TO_DATE('$(vAppStartDate)', 'DD/MM/YYYY')     

            AND  DATE <= TO_DATE('$(vAppEndDate)', 'DD/MM/YYYY');

variables-

--vAppStartDate = 01/06/2014

--vAppEndDate = 30/06/2015

Instead of using the Date column in the WHERE condition, i want to use PeriodID column existing in same table, to make the query faster.

The Period column is in below format.

PeriodID format--> 201294   //means 2012Q4. So 9 means Q

Since i am using variables, the values are always in date format, so my requirement is to first change date coming from variable to period format.

I wrote the pseudocode, because i am sure sure how to convert the date to periodID format in oracle. Also in the periodID 9 means Q.

select * from transactionTbl       

WHERE

            PeriodID >= period_function(TO_DATE('01-JUL-14', 'DD/MM/YYYY'), 'YYYYxx')

            AND  PeriodID >= period_function(TO_DATE('01-JUL-15', 'DD/MM/YYYY'), 'YYYYxx')

Please help me with the query.

Thanks!

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Assuming:

vAppStartDate = 01/06/2014

vAppEndDate = 30/06/2015

Then, before the SQL query

Let vPeriodStart = Year(vAppStartDate) & '9' & Num(Ceil(Month(vAppStartDate)/3), '00');

Let vPeriodEnd = Year(vAppEndDate ) & '9' & Num(Ceil(Month(vAppEndDate )/3), '00');

SQL

SELECT * From transactionTbl      

Where PeriodID >= $(vPeriodStart)

     And PeriodID <= $(vPeriodEnd);

If PeriodID is a a text field, add quotes:

SQL

SELECT * From transactionTbl      

Where PeriodID >= '$(vPeriodStart)'

     And PeriodID <= '$(vPeriodEnd)';


Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

2 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Assuming:

vAppStartDate = 01/06/2014

vAppEndDate = 30/06/2015

Then, before the SQL query

Let vPeriodStart = Year(vAppStartDate) & '9' & Num(Ceil(Month(vAppStartDate)/3), '00');

Let vPeriodEnd = Year(vAppEndDate ) & '9' & Num(Ceil(Month(vAppEndDate )/3), '00');

SQL

SELECT * From transactionTbl      

Where PeriodID >= $(vPeriodStart)

     And PeriodID <= $(vPeriodEnd);

If PeriodID is a a text field, add quotes:

SQL

SELECT * From transactionTbl      

Where PeriodID >= '$(vPeriodStart)'

     And PeriodID <= '$(vPeriodEnd)';


Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
bharath28
Creator
Creator
Author

Thanks a lot!