Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

SQL where operator

Good day!

Colleagues, is any way in QV script of using QV variable in SQL query ?

For example:

1. Current Load

Main:

Load

Period;

SQL SELECT *

FROM DataBase.dbo.DP3_Sales_Fact with (nolock)

where Period>='2016-08-01 00:00:00.000';

2.Neccessary Load

Main

Load

Period;

SQL SELECT *

FROM DataBase.dbo.DP3_Sales_Fact with (nolock)

where Period>=Current YearMonth;

In other words, in sql query i need load only Period for Current YearMonth (201608)

Thanks.

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Try this:

LET CurrentYearMonth = Year(today()) & month(today());

Main

Load

Period;

SQL SELECT *

FROM DataBase.dbo.DP3_Sales_Fact with (nolock)

where Period>=$(CurrentYearMonth);

View solution in original post

9 Replies
trdandamudi
Master II
Master II

May be as below:

Main

Load *

Where Period = '201608';

SQL SELECT *

FROM DataBase.dbo.DP3_Sales_Fact with (nolock);

Anonymous
Not applicable
Author

Try this:

LET CurrentYearMonth = Year(today()) & month(today());

Main

Load

Period;

SQL SELECT *

FROM DataBase.dbo.DP3_Sales_Fact with (nolock)

where Period>=$(CurrentYearMonth);

squeakie_pig
Creator II
Creator II

You can also use a variable in the sql part


Main

Load *;

SQL SELECT *

FROM DataBase.dbo.DP3_Sales_Fact

where Period >= $(vCurrentYearMonth);

richard_chilvers
Specialist
Specialist

You may need to use the TODAY() with some other functions in order to get the current Year & Month.

vishsaggi
Champion III
Champion III

What is the date format in your Period field. ?

Anonymous
Not applicable
Author

Thanks.

But Where operator in QV part of load table works longer as in SQL part.

Anonymous
Not applicable
Author

Thanks!

Anonymous
Not applicable
Author

'YYYY.MM.DD'

richard_chilvers
Specialist
Specialist

You might need to double-check this format.

Your original messages said the current load was :

1. Current Load

Main:

Load

Period;

SQL SELECT *

FROM DataBase.dbo.DP3_Sales_Fact with (nolock)

where Period>='2016-08-01 00:00:00.000';