Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

variables in sql

Hello;

I want to execute an sql script using a qlikview variable. I explain what I want with an example:

I have a qvw file called MyQVW.QVW with the variable named vDocumentName with the value DocumentName()

The script calls a SQL file:

CUSTOMER:

SQL $(Include=CUSTOMER.sql);

In the SQL file "CUSTOMER.sql" I want to use the variable vDocumentName like this way, because I use this SQL file in many QVW and I only want that return values when the QVW is MyQVW.QVW:

SELECT *

FROM tb_Customers

WHERE 'MyQVW.QVW'='$(vDocumentName)'

The script doesn't do what I want. If I use '$(vDocumentName)' in a field of the SQL file (EJ: TEST='$(vDocumentName)') returns correctly the value of the name of the file but when I use it in an expression "'MyQVW.QVW'='$(vDocumentName)'" this doesn't go well.

Someone knows what happens in my script?

Thank you,

Fernando

8 Replies
alexandros17
Partner - Champion III
Partner - Champion III

try with

SELECT *

FROM $(vDocumentName)

let me know

sasiparupudi1
Master III
Master III

May be Try

if DocumentName()='MyQVW.QVW'

tab1:

SELECT *

FROM tb_Customers;

end if

Not applicable
Author

Hello Alessandro;

This is not what I want. I want to do a select from tb_Customers.

Thanks,

Fernando

Not applicable
Author

Hello Sashidar;

The SQL file is a UNION of many SELECTs. In this select only have to return values if the document is MyQVW.

I need to have the SQL Script in a file and call it with an include sentence of QlikView.

This solution is not for my problem

Thanks,

Fernando

sasiparupudi1
Master III
Master III

can you please post a sample app with your sql file?

I am not sure if it is your expectation to write qv script in a text file? if it is then it is not going to work.

Sasi

Not applicable
Author

Hello Sasi;

I have the sql script in a text file, called CUSTOMER.sql

I call it in the qlikview script of many files qvw with the next sentence:

     SQL $(Include=CUSTOMER.sql);

I want to use the variable vDocumentName in the sql script.

I hope I have explained well.

Thanks,

Fernando




Peter_Cammaert
Partner - Champion III
Partner - Champion III

You have a SQL problem here. If I understand you well, sometimes you do want the SELECT from Customers to return rows by adding something like ...WHERE 1 = 1 (simplified) and at other times you do not want the SELECT from Customers to return rows by saying something like ... WHERE 1 = 0. Which works perfectly in a QlikView LOAD statement but aparently not in SQL. Right?

Peter

Not applicable
Author

Hello Peter;

I wanted to simplify the SQL script because I thought that would be easier to understand the problem but got the opposite effect.

My SQL have many conditions and many joins.

Really I want to do something like this:

SELECT *

FROM table1 as t1

INNER JOIN table2 as t2

     ON t1.id=....

....

WHERE condition1=true

     and condition2 =false

     .....

     and ( ('MyQVW.QVW'<>'$(vDocumentName)')

               OR

               (t1.Date >= '07/09/2015')

          )

If the QVW file is MyQVW.QVW the condition have to evaluate the condition t1.Date >= '07/09/2015' and only will give me the data of today

If the QVW file isn't MyQVW.QVW the condition is always true and don't will evaluate the condition t1.Date >= '07/09/2015' and will give me all of data



But 'MyQVW.QVW'<>'$(vDocumentName)' don't return the expected result.


Thanks,

Fernando