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: 
sculptorlv
Creator III
Creator III

SQL WHERE Date >Today()

Hello!

I have SQL table and column Date.

Is it possible to make WHERE limited selection in order to get only records with Data for last tree month..... like

InMonth(Date,Today(),-3)

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

If you are doing the comparison on the SQL Where clause, you can use the SQL syntax supported by your server - for example, in SQL Server

     SQL SELECT *

     From dbo.MyData

     Where Date >= DateAdd(m, -3, GetDate());

MySQL, Oracle etc will have different syntax - but this avoids date formatting issues.

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

View solution in original post

5 Replies
MK_QSL
MVP
MVP

Create a Variable as below

Let vTodayMinus3Month = AddMonths(Today(),-3);

Now load as per

TableName:

Load * From TableName Where Date >= '$(vTodayMinus3Month)';

Chanty4u
MVP
MVP

create a variable for that 3mnths and use it in load stmnt..

jonathandienst
Partner - Champion III
Partner - Champion III

If you are doing the comparison on the SQL Where clause, you can use the SQL syntax supported by your server - for example, in SQL Server

     SQL SELECT *

     From dbo.MyData

     Where Date >= DateAdd(m, -3, GetDate());

MySQL, Oracle etc will have different syntax - but this avoids date formatting issues.

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

Hi Ruslans,

You can do these using variables,

LET vStartDate= Monthstart(Addmonths(Today(),-3)) 

so by these variable it will consider like for today it will take then it will return , 01/10/2015

after that you can use that variable inside SQL statement by,

Last3MDATA:

LAOD *;

SQL SELECT *

From dbo.MyData

Where Date >= $(vStartdate);

Note:Please check the date format in every area(DD/MM/YYYY or YYYY-MM-DD)

Regards,

Koushik

sculptorlv
Creator III
Creator III
Author

Thanks, that is exactly what I wanted.