<?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: Extract Table Names from a Query in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1947163#M78043</link>
    <description>&lt;P&gt;Assuming your strings are mixed some with [dbo] and some without [dbo], check the attached excel file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Load
querystring
,if(index(froms,' '), subfield(froms,' ',1) , froms) as froms
,if(index(joins,' '), subfield(joins,' ',1) , joins) as joins
;
LOAD
    querystring
    ,trim(if(index(querystring,'join'),
    	TextBetween(querystring,'from','join')
        ,subfield(querystring,'from',2) ))  as froms
    ,trim(subfield(querystring,'join',2)) as joins    
FROM [lib://AttachedFiles/test.xlsx]
(ooxml, embedded labels, table is Sheet1);


exit Script;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output" style="width: 857px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/82468i68C039DD930FFBFB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Output" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Output&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jun 2022 04:56:41 GMT</pubDate>
    <dc:creator>vinieme12</dc:creator>
    <dc:date>2022-06-23T04:56:41Z</dc:date>
    <item>
      <title>Extract Table Names from a Query</title>
      <link>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1945979#M77952</link>
      <description>&lt;P&gt;Hello Qlik Experts,&lt;/P&gt;
&lt;P&gt;I have requirement here, I have a column which has the complete SQL query Executed. But I&amp;nbsp; need to extract only the table Names from that Query in the new Column. Queries can sometimes be quite complex too.&amp;nbsp; Please find below for the sample data. Please help on the below request.&lt;/P&gt;
&lt;P&gt;Input Data:&lt;/P&gt;
&lt;TABLE width="602"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="601px" height="25px"&gt;Query Statement&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="601px" height="25px"&gt;Select * from [dbo].[Customer]&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="601px" height="25px"&gt;select FirstName, LastName, b.city&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="601px" height="25px"&gt;from [dbo].[Customer] a inner join [dbo].[GeoLocation] b&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="601px" height="25px"&gt;on a.GeographyKey=b.GeographyKey&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="601px" height="25px"&gt;select distinct SupplierKey, Name, a.ProductSubcategoryKey, ProductSubcategoryName&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="601px" height="25px"&gt;from [dbo].[Product] a inner join [dbo].[Supplier] b on a.SupplierId=b.SupplierKey&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="601px" height="47px"&gt;left join [dbo].[ProductSubcategory] c on a.ProductSubcategoryKey=c.ProductSubcategoryKey&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expected Output:&lt;/P&gt;
&lt;TABLE width="1002"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="602"&gt;Query Statement&lt;/TD&gt;
&lt;TD width="400"&gt;Expected Result&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Select * from [dbo].[Customer]&lt;/TD&gt;
&lt;TD&gt;[dbo].[Customer]&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="602"&gt;select FirstName, LastName, b.city&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="602"&gt;from [dbo].[Customer] a inner join [dbo].[GeoLocation] b&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;[dbo].[Customer], [dbo].[GeoLocation]&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="602"&gt;on a.GeographyKey=b.GeographyKey&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;select distinct SupplierKey, Name, a.ProductSubcategoryKey, ProductSubcategoryName&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;from [dbo].[Product] a inner join [dbo].[Supplier] b on a.SupplierId=b.SupplierKey&lt;/TD&gt;
&lt;TD&gt;[dbo].[Product], [dbo].[Supplier], [dbo].[ProductSubcategory]&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;left join [dbo].[ProductSubcategory] c on a.ProductSubcategoryKey=c.ProductSubcategoryKey&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 21 Jun 2022 03:31:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1945979#M77952</guid>
      <dc:creator>sidhiq91</dc:creator>
      <dc:date>2022-06-21T03:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Table Names from a Query</title>
      <link>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1946494#M77983</link>
      <description>&lt;P&gt;Hello Qlik Experts,&lt;/P&gt;
&lt;P&gt;Can someone please help me with the above request? This is a very important requirement in my Project.&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 02:29:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1946494#M77983</guid>
      <dc:creator>sidhiq91</dc:creator>
      <dc:date>2022-06-22T02:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Table Names from a Query</title>
      <link>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1946553#M77992</link>
      <description>&lt;P&gt;as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Queries:
LOAD
    querystring,SubStringCount(querystring,'[dbo]') as tableCount
FROM [lib://AttachedFiles/test.xlsx]
(ooxml, embedded labels, table is Sheet1);

TableNames:
Load *
,TextBetween(querystring,'[',']',iterno()*2) as tableName
While iterno()&amp;lt;= tableCount
;
LOAD * Resident Queries;

Drop field tableCount;

exit Script;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in table chart&lt;/P&gt;
&lt;P&gt;Dimension&amp;nbsp;&lt;/P&gt;
&lt;P&gt;=querystring&lt;/P&gt;
&lt;P&gt;Measure&lt;/P&gt;
&lt;P&gt;=Concat(Distinct tableName,',')&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 06:13:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1946553#M77992</guid>
      <dc:creator>vinieme12</dc:creator>
      <dc:date>2022-06-22T06:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Table Names from a Query</title>
      <link>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1946778#M78006</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/2751"&gt;@vinieme12&lt;/a&gt;&amp;nbsp; Thank you so much. I have a question what if there were no [dbo] in the Query?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 11:33:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1946778#M78006</guid>
      <dc:creator>sidhiq91</dc:creator>
      <dc:date>2022-06-22T11:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Table Names from a Query</title>
      <link>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1947163#M78043</link>
      <description>&lt;P&gt;Assuming your strings are mixed some with [dbo] and some without [dbo], check the attached excel file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Load
querystring
,if(index(froms,' '), subfield(froms,' ',1) , froms) as froms
,if(index(joins,' '), subfield(joins,' ',1) , joins) as joins
;
LOAD
    querystring
    ,trim(if(index(querystring,'join'),
    	TextBetween(querystring,'from','join')
        ,subfield(querystring,'from',2) ))  as froms
    ,trim(subfield(querystring,'join',2)) as joins    
FROM [lib://AttachedFiles/test.xlsx]
(ooxml, embedded labels, table is Sheet1);


exit Script;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output" style="width: 857px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/82468i68C039DD930FFBFB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Output" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Output&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 04:56:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1947163#M78043</guid>
      <dc:creator>vinieme12</dc:creator>
      <dc:date>2022-06-23T04:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Table Names from a Query</title>
      <link>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1948161#M78149</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/2751"&gt;@vinieme12&lt;/a&gt;&amp;nbsp; Thank you so much for your effort to solve this for me. I did not get 100% result&amp;nbsp; as the Query is sometimes too complex. But I would still consider your solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2022 13:03:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Extract-Table-Names-from-a-Query/m-p/1948161#M78149</guid>
      <dc:creator>sidhiq91</dc:creator>
      <dc:date>2022-06-25T13:03:38Z</dc:date>
    </item>
  </channel>
</rss>

