<?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: Is it possible to use a CASE statement in a SQL query in Connectivity &amp; Data Prep</title>
    <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411523#M3071</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all, I think I have handle on it now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 21 Aug 2017 16:15:06 GMT</pubDate>
    <dc:creator>lthurman</dc:creator>
    <dc:date>2017-08-21T16:15:06Z</dc:date>
    <item>
      <title>Is it possible to use a CASE statement in a SQL query</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411516#M3064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to run this query in the Data Load Editor of Desktop,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT Sum(CASE WHEN CategoryKey = 3 THEN TotAmt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE 0.00 END),&lt;/P&gt;&lt;P&gt;Sum(CASE WHEN CategoryKey = 3 THEN TotBilledUnits&amp;nbsp; ELSE 0&amp;nbsp;&amp;nbsp;&amp;nbsp; END),&lt;/P&gt;&lt;P&gt;Sum(CASE WHEN CategoryKey = 5 THEN TotAmt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE 0.00 END),&lt;/P&gt;&lt;P&gt;Sum(CASE WHEN CategoryKey = 5 THEN TotBilledUnits&amp;nbsp; ELSE 0&amp;nbsp;&amp;nbsp;&amp;nbsp; END),&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM EDM_ExpCatMdlAgg&lt;/P&gt;&lt;P&gt;WHERE FleetId = '3TPA'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But, I get this error:&lt;/P&gt;&lt;P&gt;The following error occurred:&lt;/P&gt;&lt;P class="edc_error" style="padding: 0 10px; color: #595959; font-family: 'Courier New'; font-size: 15px; background: rgba(255, 38, 38, 0.2);"&gt;Connector reply error: Unable to get column information for the fields that are used in the query: ERROR [HY000] [Qlik][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Incorrect syntax near '='. ERROR [HY000] [Qlik][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Statement(s) could not be prepared.&lt;/P&gt;&lt;P class="headline edc_error" style="padding: 0 10px; font-weight: bolder; color: #595959; font-family: 'Courier New'; font-size: 15px; background: rgba(255, 38, 38, 0.2);"&gt;The error occurred here:&lt;/P&gt;&lt;P class="edc_error" style="padding: 0 10px; color: #595959; font-family: 'Courier New'; font-size: 15px; background: rgba(255, 38, 38, 0.2);"&gt;?&lt;/P&gt;&lt;P class="headline undefined" style="padding: 0 10px; font-weight: bolder; color: #595959; font-family: 'Courier New'; font-size: 15px;"&gt;Data has not been loaded. Please correct the error and try loading again.&lt;/P&gt;&lt;P class="headline undefined" style="padding: 0 10px; font-weight: bolder; color: #595959; font-family: 'Courier New'; font-size: 15px;"&gt;&lt;/P&gt;&lt;P class="headline undefined" style="padding: 0 10px; font-weight: bolder; color: #595959; font-family: 'Courier New'; font-size: 15px;"&gt;&lt;/P&gt;&lt;P class="headline undefined" style="padding: 0 10px; font-weight: bolder; color: #595959; font-family: 'Courier New'; font-size: 15px;"&gt;I can run simpler queries, but this one fails and I'm not sure why. I guess my bigger question is how complex a query does the MS SQL Server driver handle?&lt;/P&gt;&lt;P class="headline undefined" style="padding: 0 10px; font-weight: bolder; color: #595959; font-family: 'Courier New'; font-size: 15px;"&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Lorenzo Thurman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2017 14:30:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411516#M3064</guid>
      <dc:creator>lthurman</dc:creator>
      <dc:date>2017-08-16T14:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a CASE statement in a SQL query</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411517#M3065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have an extra comma between your last Sum() and the From clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not have a definitive answer about the maximum level of complexity that the SQL Server ODBC driver can handle.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2017 20:45:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411517#M3065</guid>
      <dc:creator />
      <dc:date>2017-08-16T20:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a CASE statement in a SQL query</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411518#M3066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. I’m new to Qlik and am in the “can’t see the forest for the trees” right now. I caught the error. But maybe I should rephrase my other question:&lt;/P&gt;&lt;P&gt;If using the MS SQL Server driver, should I expect any query that works in 2014 to work in Qlik?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2017 20:55:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411518#M3066</guid>
      <dc:creator>lthurman</dc:creator>
      <dc:date>2017-08-16T20:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a CASE statement in a SQL query</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411519#M3067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I do not know.&amp;nbsp; I am not familiar with the ODBC driver you mentioned.&amp;nbsp; I have run into other cases with other drivers where they could not handle large volumes of data or BLOBS or Common Table Expressions or syntax that was very database specific.&amp;nbsp; These are ODBC issues rather than Qlik (or any other client) issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to Qlik, too.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2017 21:30:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411519#M3067</guid>
      <dc:creator />
      <dc:date>2017-08-16T21:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a CASE statement in a SQL query</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411520#M3068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is not a limitation of Qlik and what you write in the load editor. The entire text between SQL and the following semicolon is sent as is to the ODBC driver and it is up to the ODBC-driver and the back-end SQL Server to just execute the TSQL you have written and return results. The error message indicates that you have a problem with your syntax. Have you tried to run the exact same query in a Microsoft query tool like the Microsoft SQL Server Management Studio and got it to work? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The query seems odd to me as you are using the aggregation function Sum() without having a GROUP BY clause in the SQL. Is that really valid TSQL?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try writing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;SELECT&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; CASE WHEN CategoryKey = 3 THEN TotAmt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE 0.00 END,&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; CASE WHEN CategoryKey = 3 THEN TotBilledUnits&amp;nbsp; ELSE 0&amp;nbsp;&amp;nbsp;&amp;nbsp; END,&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; CASE WHEN CategoryKey = 5 THEN TotAmt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE 0.00 END,&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; CASE WHEN CategoryKey = 5 THEN TotBilledUnits&amp;nbsp; ELSE 0&amp;nbsp;&amp;nbsp;&amp;nbsp; END&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;FROM EDM_ExpCatMdlAgg&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; WHERE FleetId = '3TPA'&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;You should expect that most queries that work from other query tools work within the Qlik Load Editor. However there are some limitations:&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;- It has to be a single SQL statement - not multiple&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;- If you have a query that returns multiple columns with the same column name but prefixed with a different table named it will run well with most query tools but Qlik can't figure that out because it strips away the qualifier (the table name) and will get columns which have identical names which it doesn't like.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2017 22:41:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411520#M3068</guid>
      <dc:creator>petter</dc:creator>
      <dc:date>2017-08-16T22:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a CASE statement in a SQL query</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411521#M3069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are missing group by statement in your query. &lt;/P&gt;&lt;P&gt;Usually the syntax is &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select&lt;/P&gt;&lt;P&gt;Dim1,&lt;/P&gt;&lt;P&gt;Dim2,&lt;/P&gt;&lt;P&gt;Sum (value)&lt;/P&gt;&lt;P&gt;From your table &lt;/P&gt;&lt;P&gt;Where keyfield='something'&lt;/P&gt;&lt;P&gt;Group by&lt;/P&gt;&lt;P&gt;Dim1,&lt;/P&gt;&lt;P&gt;Dim2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Aug 2017 14:20:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411521#M3069</guid>
      <dc:creator>sasiparupudi1</dc:creator>
      <dc:date>2017-08-20T14:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a CASE statement in a SQL query</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411522#M3070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Lorenzo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I looked this thread over and Petter has some solid advice on running in SQL Server Query analyzer environment to test your SQLs, I always do that. The Group by is something to consider, it looked like you were just summing 4 buckets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe you need to supply an alias name with an AS clause for each of you SUM statements.&lt;/P&gt;&lt;P&gt;Your code with an alias added is below in bold and italics:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT Sum(CASE WHEN CategoryKey = 3 THEN TotAmt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE 0.00 END)&lt;EM&gt;&lt;STRONG&gt; AS 'Cat3 TotAmt',&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Sum(CASE WHEN CategoryKey = 3 THEN TotBilledUnits&amp;nbsp; ELSE 0&amp;nbsp;&amp;nbsp;&amp;nbsp; END) &lt;STRONG&gt;&lt;EM&gt;AS 'Cat3 TotBilledUnits ,&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Sum(CASE WHEN CategoryKey = 5 THEN TotAmt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE 0.00 END) &lt;STRONG&gt;&lt;EM&gt;AS 'Cat5 TotAmt',&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Sum(CASE WHEN CategoryKey = 5 THEN TotBilledUnits&amp;nbsp; ELSE 0&amp;nbsp;&amp;nbsp;&amp;nbsp; END)&lt;STRONG&gt;&lt;EM&gt;AS 'Cat5 TotBilledUnits &lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM EDM_ExpCatMdlAgg&lt;/P&gt;&lt;P&gt;WHERE FleetId = '3TPA'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm pretty sure that will solve&amp;nbsp; your issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Patrick&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Aug 2017 21:46:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411522#M3070</guid>
      <dc:creator>duffman1968</dc:creator>
      <dc:date>2017-08-20T21:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a CASE statement in a SQL query</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411523#M3071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all, I think I have handle on it now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Aug 2017 16:15:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411523#M3071</guid>
      <dc:creator>lthurman</dc:creator>
      <dc:date>2017-08-21T16:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a CASE statement in a SQL query</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411524#M3072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please close the thread by marking it answered &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Aug 2017 07:52:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Is-it-possible-to-use-a-CASE-statement-in-a-SQL-query/m-p/1411524#M3072</guid>
      <dc:creator>petter</dc:creator>
      <dc:date>2017-08-22T07:52:45Z</dc:date>
    </item>
  </channel>
</rss>

