<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: using a value from an xml file as a parameter in tsmsqlinput in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/using-a-value-from-an-xml-file-as-a-parameter-in-tsmsqlinput/m-p/2349305#M116304</link>
    <description>&lt;P&gt;So I guess you are using a tRouteInput to receive the XML into the Talend Job. Is that right? Do you have the Simple Expression you are using? Is this working? Can you see the XML using&amp;nbsp; a tLogRow?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;If the answer to the above is yes, then can you tell me if the XML is held as a String or as an XML Document? It shouldn't matter too much, but it is good to know.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The next thing to do is to extract your id. Do you know XPath? You can use this with either XML stored as a Document or a String. You would use a tExtractXMLField component for this (take a look here: &lt;A href="https://help.talend.com/reader/hm5FaPiiOP31nUYHph0JwQ/Pc9RZi6IiWw1Kb~Jf0bE0Q).&amp;nbsp;" target="_blank" rel="nofollow noopener noreferrer"&gt;https://help.talend.com/reader/hm5FaPiiOP31nUYHph0JwQ/Pc9RZi6IiWw1Kb~Jf0bE0Q).&amp;nbsp;&lt;/A&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Once you have your id in a row you can use a tSetGlobalVar component to set a globalMap value. The globalMap is a hashmap that can be used (like any Java hashmap) in your database query.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;One last thing to remember. Your DB query is essentially a Java String. You are using Java to build a SQL query. SO if you want the following query.....&lt;/P&gt; 
&lt;PRE&gt;Select
id,
name,
address1,
address2
From person
Where name = 'Richard'&lt;/PRE&gt; 
&lt;P&gt;....but want to make the Where clause dynamic, you need to build it in your DB component like this (assuming the name is stored in the globalMap with a key of "name")....&lt;/P&gt; 
&lt;PRE&gt;"Select
id,
name,
address1,
address2
From person
Where name = '" + ((String)globalMap.get("name")) + "'"&lt;/PRE&gt; 
&lt;P&gt;Pay attention to the single quotes inside the double quotes!!&lt;/P&gt;</description>
    <pubDate>Wed, 04 Apr 2018 17:22:34 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-04-04T17:22:34Z</dc:date>
    <item>
      <title>using a value from an xml file as a parameter in tsmsqlinput</title>
      <link>https://community.qlik.com/t5/Talend-Studio/using-a-value-from-an-xml-file-as-a-parameter-in-tsmsqlinput/m-p/2349304#M116303</link>
      <description>&lt;P&gt;I am calling a DI job from a camel route, and passing an xml file structured like this: &amp;lt;patient action="insert" id="30"/&amp;gt;&lt;/P&gt; 
&lt;P&gt;What I need to do is pull the data for the id (30) from a SQL Server database and put to Salesforce.&lt;/P&gt; 
&lt;P&gt;I am having a difficult time using the id value and setting a dynamic sql query in the tMSSQLinput.&lt;/P&gt; 
&lt;P&gt;How do I set variables and assign them from the xml file to parameters in the query of the&amp;nbsp;tMSSQLinput?&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 08:27:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/using-a-value-from-an-xml-file-as-a-parameter-in-tsmsqlinput/m-p/2349304#M116303</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T08:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: using a value from an xml file as a parameter in tsmsqlinput</title>
      <link>https://community.qlik.com/t5/Talend-Studio/using-a-value-from-an-xml-file-as-a-parameter-in-tsmsqlinput/m-p/2349305#M116304</link>
      <description>&lt;P&gt;So I guess you are using a tRouteInput to receive the XML into the Talend Job. Is that right? Do you have the Simple Expression you are using? Is this working? Can you see the XML using&amp;nbsp; a tLogRow?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;If the answer to the above is yes, then can you tell me if the XML is held as a String or as an XML Document? It shouldn't matter too much, but it is good to know.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The next thing to do is to extract your id. Do you know XPath? You can use this with either XML stored as a Document or a String. You would use a tExtractXMLField component for this (take a look here: &lt;A href="https://help.talend.com/reader/hm5FaPiiOP31nUYHph0JwQ/Pc9RZi6IiWw1Kb~Jf0bE0Q).&amp;nbsp;" target="_blank" rel="nofollow noopener noreferrer"&gt;https://help.talend.com/reader/hm5FaPiiOP31nUYHph0JwQ/Pc9RZi6IiWw1Kb~Jf0bE0Q).&amp;nbsp;&lt;/A&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Once you have your id in a row you can use a tSetGlobalVar component to set a globalMap value. The globalMap is a hashmap that can be used (like any Java hashmap) in your database query.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;One last thing to remember. Your DB query is essentially a Java String. You are using Java to build a SQL query. SO if you want the following query.....&lt;/P&gt; 
&lt;PRE&gt;Select
id,
name,
address1,
address2
From person
Where name = 'Richard'&lt;/PRE&gt; 
&lt;P&gt;....but want to make the Where clause dynamic, you need to build it in your DB component like this (assuming the name is stored in the globalMap with a key of "name")....&lt;/P&gt; 
&lt;PRE&gt;"Select
id,
name,
address1,
address2
From person
Where name = '" + ((String)globalMap.get("name")) + "'"&lt;/PRE&gt; 
&lt;P&gt;Pay attention to the single quotes inside the double quotes!!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 17:22:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/using-a-value-from-an-xml-file-as-a-parameter-in-tsmsqlinput/m-p/2349305#M116304</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-04-04T17:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: using a value from an xml file as a parameter in tsmsqlinput</title>
      <link>https://community.qlik.com/t5/Talend-Studio/using-a-value-from-an-xml-file-as-a-parameter-in-tsmsqlinput/m-p/2349306#M116305</link>
      <description>&lt;P&gt;Thank you Rhall - very helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;yes I am using a tRouteInput to receive the XML into the Talend Job, and the XML is there.&lt;/P&gt;
&lt;P&gt;Your solution works great, and I also went another route which also works:&lt;/P&gt;
&lt;P&gt;1: added a tXMLMap to the right of the tRouteInput, imported the XML structure to the input side, then created an output table and mapped the id field to the the field "patient_id" on the output side.&lt;/P&gt;
&lt;P&gt;2: Added a tJavaRow to the output of the tXMLMap &amp;amp; set a context variable like so: context.patient_id = out1.patient_id.toString();&lt;/P&gt;
&lt;P&gt;3: once that sub-routine completes, used onSubJobOK to goto tMSSQLInput and set the query:&lt;/P&gt;
&lt;P&gt;"SELECT PatientID,Gender ...&lt;BR /&gt;&amp;nbsp; FROM Patients where PatientID = " + context.patient_id&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the quick response!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 22:13:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/using-a-value-from-an-xml-file-as-a-parameter-in-tsmsqlinput/m-p/2349306#M116305</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-04-04T22:13:12Z</dc:date>
    </item>
  </channel>
</rss>

