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: 
Anonymous
Not applicable

how to pass a variable in a tMSSQLInput based on a query ?

hello
I would like to use one SQL query that could vary based upon one variable, how can I pass this parameter in the SQL query ?
David
Labels (2)
25 Replies
Anonymous
Not applicable
Author

Perl or Java project?
Anonymous
Not applicable
Author

Java :
"SELECT * from TABLE
where S.CODE_PER IN ('2007070','2007080','2007090') "
I need to pass ('2007070','2007080','2007090') as a variable : current month, month -1 and month -2 as YYYYMM0
_AnonymousUser
Specialist III
Specialist III

Hi dcopp.
Try this (I've discover it today):
"SELECT * from TABLE
where S.CODE_PER IN ('"+context.getProperty("date")+"',ecc) "
Bye
Anonymous
Not applicable
Author

hello
How did you define your context ?
I don't get any rows with such script, more the 'ecc' column is unknown to me
Anybody succeeded in passing a variable value into a SQL script ?
Anonymous
Not applicable
Author

Under tab "Repository" there is an icon called "Contexts". Right click->create context
Bye
c0utta
Creator
Creator

dcopp,
All my queries use context variables with MSSQL - have a look at my post 1164. The screen print will show you how to use context variables with in a query. As long as the query resolves to a string, that's all that matters.
Can I also be so bold as to suggest to read the User Guide? Contexts are clearly documented in there, as are creation of context variables.
Cheers,
c0utta
Anonymous
Not applicable
Author

Ok, I have tried to find the answer in many places in this forum but I haven't been successful.
I have two table: one with the unique keys and a second with the associated values.
So I use a first tMysqlInput to get the keys (select id from id_table) --> Iterate --> tMysqlInput (select data from data_table where data_id = tMysqlInput.id)
My issue is that I don't know how to iterate on the id result from the first query and use the query result as a parameter in the second component.
Anonymous
Not applicable
Author

Hello raton
So I use a first tMysqlInput to get the keys (select id from id_table) --> Iterate --> tMysqlInput (select data from data_table where data_id = tMysqlInput.id)

For example:
tMysqlInput--row1-->tLogRow
|
iterate
|
tMySQLInput("select data from data_table where data_id ="+String.valueOf(row1.id))
Best regards

shong
Anonymous
Not applicable
Author

I can feel that I am getting a lot closer to the solution. 0683p000009MACn.png
The equivalent of that line "tMySQLInput("select data from data_table where data_id ="+String.valueOf(row1.id)) " for Perl would be ... ??
(sorry for the extra question, I just saw this topic was tagged "java" ... )