Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
nihhalmca
Specialist II
Specialist II

Where condition for Previous Quarter data dynamically while extracting from SQL Server

Hi All,

How to write condition at SQL Query to extract only Previous Quarter data (Dynamically) from SQL Server to QlikView.

Date filed format '201911'

Thanks, Nihhal.

4 Replies
QlikJunkie
Contributor
Contributor

 

Try if it helps....!!

 

SELECT * FROM
table_name
WHERE
TO_DATE( your_date_field, 'YYYYMM' )

BETWEEN trunc(add_months(SYSDATE,-3),'Q') AND trunc(add_months(SYSDATE,0),'Q') - ( 1 / ( 24 * 60 * 60 ) )

(Oracle SQl Syntax, change function syntax if you are on MS SQL Server)

nihhalmca
Specialist II
Specialist II
Author

Thanks for response, can you share SQL Server syntax if you have idea actually i am new to it.

QlikJunkie
Contributor
Contributor

 

SQL Server...!

 

SELECT * FROM
"table_name"
WHERE
CONVERT(DATETIME, "your_date_field", 'YYYYMM' )
BETWEEN trunc(dateadd(month, -3, GETDATE()),'Q') AND trunc(dateadd(month, 0, GETDATE()),'Q') - ( 1 / ( 24 * 60 * 60 ) )

Brett_Bleess
Former Employee
Former Employee

Nihhal, did the last post get you what you needed?  If so, do not forget to come back to the thread and use the Accept as Solution button on the post to mark it and give credit to the poster as well as let the other Community Members know that it did work.  

Here is something else though that you may want to consider:

https://community.qlik.com/t5/Qlik-Design-Blog/Preceding-Load/ba-p/1469534

That might be another way to do things.

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.