[resolved] Context variable in SQL syntax

One Star

[resolved] Context variable in SQL syntax

Hello.
Could anyone help me run the following SQL instruction please?
"SELECT *
FROM " + context.current_TABLE "

Context variable "current_TABLE" is defined in the parent job.
Which is the error in my SQL syntax ?
Thank you very much.
Five Stars

Re: [resolved] Context variable in SQL syntax

You just seem to have an extra double-quote - context.current_TABLE "
I'd recommend not using "*" and naming your fields. It will have some heartache later.
One Star

Re: [resolved] Context variable in SQL syntax

diarux - and make sure you're passing your context variables from the Parent to the child by checking the checkbox on the tRunJob component (transmit whole context). Other than that, should be "SELECT * FROM " + context.current_TABLE
One Star

Re: [resolved] Context variable in SQL syntax

Hello.
Even if I use the following syntax, I still have an error :
"SELECT * FROM " + context.current_TABLE
I passed my context variable from the Parent to the child.
Context variable "current_TABLE" is defined as follows :
((String)globalMap.get("row1.nom_table"))
I don't understand why it doesn't work.
Five Stars

Re: [resolved] Context variable in SQL syntax

You haven't actually said what the error is...
Two Stars

Re: [resolved] Context variable in SQL syntax

Hi diarux,
Use the fallowing syntax for using context variables in sql.
"SELECT * FROM \""+context.current_TABLE+"\"".
Make sure that you have to enable transmit whole context check box in setting of tRunJob in parent job.

Regards,
Bhanu.
Moderator

Re: [resolved] Context variable in SQL syntax

Hi diarux,
Please upload your current job screenshots into forum so that we can see if there is wrong setting in your work flow.
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: [resolved] Context variable in SQL syntax

Hello.
Could you please take a look at the attached screenshot ?
Thank you for your help.
Seventeen Stars

Re: [resolved] Context variable in SQL syntax

hi all,
no screenshoot available Smiley Sad (be sure about max size)
check the value passed by 'father job' to be sure it's not null
read some help from Talend :
https://help.talend.com/search/all?query=Passing+a+value+from+a+parent+Job+to+a+child+Job&content-la...
regards
laurent
One Star

Re: [resolved] Context variable in SQL syntax

current_TABLE is defined in parent job as :
(String)globalMap.get("my-Table.nom_table")
num_utilisateur is defined in parent job as:
Integer.parseInt(jobName.substring(1,2))
Error message when running child job :
Exception in component tMSSqlInput_1
java.sql.SQLException: Syntaxe incorrecte vers 'FROM'

Still doesn't work.
Five Stars

Re: [resolved] Context variable in SQL syntax

It must be a simple error.
Add a tContextDump just before your SQL call to check the values are set as you expect.