<?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: SQL Union all plus variable in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399079#M812268</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the quick response Peter. I am assuming something like below? It is still giving me the error message '&lt;STRONG&gt;ErrorSource: Microsoft SQL Server Native Client 11.0, ErrorMsg: Incorrect syntax near ')'.&lt;/STRONG&gt; Not sure how can I identify which row this error is. I looked line by line but I can't find anything obvious.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&lt;STRONG&gt;LET&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ExtractDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39)&amp;amp;'2017/09/15'&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39));&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LET&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ActualWeekEndDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;WeekEnd&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Today&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;()),'YYYY/MM/DD')) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39);&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Actual and planned activity&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt; ActivityvPlan:&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;Load&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; *,&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Week Ending]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,'DD/MM/YYYY') &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;WeekEnding&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,&lt;BR /&gt; 'Past' &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;;&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;BR /&gt; SELECT&lt;BR /&gt; AP.[FinYear],&lt;BR /&gt; AP.[Month_Name],&lt;BR /&gt; AP.[Week Ending],&lt;BR /&gt; AP.[Site],&lt;BR /&gt; AP.[Activity Type] AS 'Activity Type (Original)',&lt;BR /&gt; CASE&lt;BR /&gt; WHEN AP.[Activity Type] = 'OP' THEN 'Outpatient'&lt;BR /&gt; WHEN AP.[Activity Type] = 'DayCase' THEN 'Day Case'&lt;BR /&gt; ELSE AP.[Activity Type] &lt;BR /&gt; END AS 'Activity Type',&lt;BR /&gt; UPPER(AP.[Specialty]) as [Specialty],&lt;BR /&gt; AP.[NC],&lt;BR /&gt; AP.[Plan],&lt;BR /&gt; CASE WHEN AP.[Week Ending] &amp;gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(@ActualWeekEndDate)&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; THEN 0 ELSE AP.[Actual] END AS 'Actual',&lt;BR /&gt; AP.[Actual] as 'RawActuals',&lt;BR /&gt; NULL as Booked,&lt;BR /&gt; GETDATE() AS 'Run Date',&lt;BR /&gt; 'Actual and Planned' AS 'Category'&lt;BR /&gt; --ISNULL(MSI.[Site],'Unknown') AS 'Site for Reporting'&lt;BR /&gt; FROM [BH_INFORMATION].[DBO].[PLAN_AND_ACTUAL] AS AP &lt;BR /&gt; LEFT JOIN [BH_INFORMATION].[dbo].[DivisionLookup] DL ON AP.Specialty = DL.SPECIALTY&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Link to site look-up table&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;LEFT OUTER JOIN [BH_PERFORMANCE].[dbo].[LKP_Site] AS LS&lt;BR /&gt; ON AP.[Site] = LS.[Raw Value]&lt;BR /&gt; AND LS.[Is Latest] = 'Y'&lt;BR /&gt; WHERE&lt;BR /&gt; AP.FinYear &amp;gt;= '2017/18'&lt;BR /&gt; AND AP.[Activity Type] &amp;lt;&amp;gt; 'Other';&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Future activity&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LET&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ExtractDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39)&amp;amp;'2017/09/15'&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39));&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//&lt;BR /&gt; //&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LET&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ActualWeekEndDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;WeekEnd&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Today&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;()),'YYYY/MM/DD')) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39);&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;CONCATENATE&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; (ActivityvPlan)&lt;BR /&gt; &lt;BR /&gt; FutureActivity:&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LOAD&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; *,&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Week Ending]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,'DD/MM/YYYY') &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;WeekEnding&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,&lt;BR /&gt; 'Past' &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;;&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt; SELECT&lt;BR /&gt; F.[FinYear],&lt;BR /&gt; F.[Month_Name],&lt;BR /&gt; F.[Week Ending],&lt;BR /&gt; F.[Site],&lt;BR /&gt; F.[Activity Type] AS 'Activity Type (Original)',&lt;BR /&gt; CASE&lt;BR /&gt; WHEN F.[Activity Type] = 'Daycases' THEN 'Day Case'&lt;BR /&gt; WHEN F.[Activity Type] = 'Elective Inpatients' THEN 'Elective'&lt;BR /&gt; WHEN F.[Activity Type] IN ('First Outpatient Attendances','Outpatient procedures','Subsequent outpatient Attendances') THEN 'Outpatient'&lt;BR /&gt; ELSE 'Other' END AS 'Activity Type',&lt;BR /&gt; F.[Specialty],&lt;BR /&gt; DL.[DIVISION] AS Division,&lt;BR /&gt; NULL AS 'NC',&lt;BR /&gt; NULL AS 'Plan', &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Note: definitely do not use planned data in this future table as the planned fields are not correct in it&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;F.[Booked Activity] AS 'Actual',&lt;BR /&gt; F.Rundate&lt;/SPAN&gt;&lt;STRONG style=": ; color: #ff0000; font-size: 8pt;"&gt;)&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; AS 'Run Date',&lt;BR /&gt; 'Future Booked' AS 'Category',&lt;BR /&gt; ISNULL(MSI.[Site],'Unknown') AS 'Site for Reporting'&lt;BR /&gt; &lt;BR /&gt; FROM&lt;BR /&gt; [BH_INFORMATION].[DBO].[DASHBOARD_FUTURE] AS F&lt;BR /&gt; LEFT JOIN [BH_INFORMATION].[dbo].[DivisionLookup] DL ON F.Specialty = DL.SPECIALTY&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Link to site look-up table&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;LEFT OUTER JOIN [BH_PERFORMANCE].[dbo].[LKP_Site] AS LS&lt;BR /&gt; ON F.[Site] = LS.[Raw Value]&lt;BR /&gt; AND LS.[Is Latest] = 'Y'&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Link to master site table&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;LEFT OUTER JOIN&lt;BR /&gt; [BH_PERFORMANCE].[dbo].[Master_Site] AS MSI&lt;BR /&gt; ON LS.[Mapped Value] = MSI.[Site Original]&lt;BR /&gt; AND MSI.[Is Latest] = 'Y'&lt;BR /&gt; &lt;BR /&gt; WHERE&lt;BR /&gt; F.FinYear &amp;gt;= '2017/18'&lt;BR /&gt; AND CAST(F.Rundate AS DATE) = @ExtractDate&lt;BR /&gt; AND (CASE&lt;BR /&gt; WHEN F.[Activity Type] = 'Daycases' THEN 'Day Case'&lt;BR /&gt; WHEN F.[Activity Type] = 'Elective Inpatients' THEN 'Elective'&lt;BR /&gt; WHEN F.[Activity Type] IN ('First Outpatient Attendances','Outpatient procedures','Subsequent outpatient Attendances') THEN 'Outpatient'&lt;BR /&gt; ELSE 'Other' END) &amp;lt;&amp;gt; 'Other'; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Sep 2017 15:41:34 GMT</pubDate>
    <dc:creator>infock12</dc:creator>
    <dc:date>2017-09-22T15:41:34Z</dc:date>
    <item>
      <title>SQL Union all plus variable</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399077#M812266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Times New Roman; font-size: 12pt;"&gt;&amp;nbsp; Hi all,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Times New Roman; font-size: 12pt;"&gt;I am using the below script but it gives me an error message Syntax error, misplaced/missing FROM: Concatenate(ActivityvPlan). Please could you let me know if there is anything wrong with the below? Many thanks.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;BR /&gt; &lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LET&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ExtractDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39)&amp;amp;'2017/09/15'&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39));&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LET&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ActualWeekEndDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;WeekEnd&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Today&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;()),'YYYY/MM/DD')) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39);&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Actual and planned activity&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt; ActivityvPlan:&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;Load&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; *,&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Week Ending]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,'DD/MM/YYYY') &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;WeekEnding&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,&lt;BR /&gt; 'Past' &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;;&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;BR /&gt; SELECT&lt;BR /&gt; AP.[FinYear],&lt;BR /&gt; AP.[Month_Name],&lt;BR /&gt; AP.[Week Ending],&lt;BR /&gt; AP.[Site],&lt;BR /&gt; AP.[Activity Type] AS 'Activity Type (Original)',&lt;BR /&gt; CASE&lt;BR /&gt; WHEN AP.[Activity Type] = 'OP' THEN 'Outpatient'&lt;BR /&gt; WHEN AP.[Activity Type] = 'DayCase' THEN 'Day Case'&lt;BR /&gt; ELSE AP.[Activity Type] &lt;BR /&gt; END AS 'Activity Type',&lt;BR /&gt; UPPER(AP.[Specialty]) as [Specialty],&lt;BR /&gt; AP.[NC],&lt;BR /&gt; AP.[Plan],&lt;BR /&gt; CASE WHEN AP.[Week Ending] &amp;gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(@ActualWeekEndDate)&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; THEN 0 ELSE AP.[Actual] END AS 'Actual',&lt;BR /&gt; AP.[Actual] as 'RawActuals',&lt;BR /&gt; NULL as Booked,&lt;BR /&gt; GETDATE() AS 'Run Date',&lt;BR /&gt; 'Actual and Planned' AS 'Category'&lt;BR /&gt; --ISNULL(MSI.[Site],'Unknown') AS 'Site for Reporting'&lt;BR /&gt; FROM [BH_INFORMATION].[DBO].[PLAN_AND_ACTUAL] AS AP &lt;BR /&gt; LEFT JOIN [BH_INFORMATION].[dbo].[DivisionLookup] DL ON AP.Specialty = DL.SPECIALTY&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Link to site look-up table&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;LEFT OUTER JOIN [BH_PERFORMANCE].[dbo].[LKP_Site] AS LS&lt;BR /&gt; ON AP.[Site] = LS.[Raw Value]&lt;BR /&gt; AND LS.[Is Latest] = 'Y'&lt;BR /&gt; WHERE&lt;BR /&gt; AP.FinYear &amp;gt;= '2017/18'&lt;BR /&gt; AND AP.[Activity Type] &amp;lt;&amp;gt; 'Other';&lt;BR /&gt; &lt;BR /&gt; CONCATENATE (ActivityvPlan)&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Future activity&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;LET @ExtractDate = Text(Chr(39)&amp;amp;'2017/09/15'&amp;amp;Chr(39));&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LET&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ActualWeekEndDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;WeekEnd&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Today&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;()),'YYYY/MM/DD')) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39);&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LOAD&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; *,&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Week Ending]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,'DD/MM/YYYY') &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;WeekEnding&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,&lt;BR /&gt; 'Past' &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;;&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt; SELECT&lt;BR /&gt; F.[FinYear],&lt;BR /&gt; F.[Month_Name],&lt;BR /&gt; F.[Week Ending],&lt;BR /&gt; F.[Site],&lt;BR /&gt; F.[Activity Type] AS 'Activity Type (Original)',&lt;BR /&gt; CASE&lt;BR /&gt; WHEN F.[Activity Type] = 'Daycases' THEN 'Day Case'&lt;BR /&gt; WHEN F.[Activity Type] = 'Elective Inpatients' THEN 'Elective'&lt;BR /&gt; WHEN F.[Activity Type] IN ('First Outpatient Attendances','Outpatient procedures','Subsequent outpatient Attendances') THEN 'Outpatient'&lt;BR /&gt; ELSE 'Other' END AS 'Activity Type',&lt;BR /&gt; F.[Specialty],&lt;BR /&gt; DL.[DIVISION] AS Division,&lt;BR /&gt; NULL AS 'NC',&lt;BR /&gt; NULL AS 'Plan', --Note: definitely do not use planned data in this future table as the planned fields are not correct in it&lt;BR /&gt; F.[Booked Activity] AS 'Actual',&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--(F.Rundate) AS 'Run Date',&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;'Future Booked' AS 'Category',&lt;BR /&gt; ISNULL(MSI.[Site],'Unknown') AS 'Site for Reporting'&lt;BR /&gt; &lt;BR /&gt; FROM&lt;BR /&gt; [BH_INFORMATION].[DBO].[DASHBOARD_FUTURE] AS F&lt;BR /&gt; LEFT JOIN [BH_INFORMATION].[dbo].[DivisionLookup] DL ON F.Specialty = DL.SPECIALTY&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Link to site look-up table&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;LEFT OUTER JOIN [BH_PERFORMANCE].[dbo].[LKP_Site] AS LS&lt;BR /&gt; ON F.[Site] = LS.[Raw Value]&lt;BR /&gt; AND LS.[Is Latest] = 'Y'&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Link to master site table&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;LEFT OUTER JOIN&lt;BR /&gt; [BH_PERFORMANCE].[dbo].[Master_Site] AS MSI&lt;BR /&gt; ON LS.[Mapped Value] = MSI.[Site Original]&lt;BR /&gt; AND MSI.[Is Latest] = 'Y'&lt;BR /&gt; &lt;BR /&gt; WHERE&lt;BR /&gt; F.FinYear &amp;gt;= '2017/18'&lt;BR /&gt; AND CAST(F.Rundate AS DATE) = @ExtractDate&lt;BR /&gt; AND (CASE&lt;BR /&gt; WHEN F.[Activity Type] = 'Daycases' THEN 'Day Case'&lt;BR /&gt; WHEN F.[Activity Type] = 'Elective Inpatients' THEN 'Elective'&lt;BR /&gt; WHEN F.[Activity Type] IN ('First Outpatient Attendances','Outpatient procedures','Subsequent outpatient Attendances') THEN 'Outpatient'&lt;BR /&gt; ELSE 'Other' END) &amp;lt;&amp;gt; 'Other'; &lt;/SPAN&gt;&lt;SPAN style="color: #000000; font-family: Times New Roman; font-size: 12pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0px 0px 10pt;"&gt;&lt;SPAN style="color: #000000; font-family: Calibri; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Times New Roman; font-size: 12pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2020 16:16:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399077#M812266</guid>
      <dc:creator>infock12</dc:creator>
      <dc:date>2020-11-25T16:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Union all plus variable</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399078#M812267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;CONCATENATE is a prefix for a LOAD statement. If we keep that in mind, then why are there two complete LET statements between the CONCATENATE (ActivityvPlan) prefix and the next LOAD?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Place the CONCATENATE(ActivityvPlan) line two statements lower, and all will be fine (with the statement syntax, that is)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 15:08:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399078#M812267</guid>
      <dc:creator>Peter_Cammaert</dc:creator>
      <dc:date>2017-09-22T15:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Union all plus variable</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399079#M812268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the quick response Peter. I am assuming something like below? It is still giving me the error message '&lt;STRONG&gt;ErrorSource: Microsoft SQL Server Native Client 11.0, ErrorMsg: Incorrect syntax near ')'.&lt;/STRONG&gt; Not sure how can I identify which row this error is. I looked line by line but I can't find anything obvious.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&lt;STRONG&gt;LET&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ExtractDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39)&amp;amp;'2017/09/15'&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39));&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LET&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ActualWeekEndDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;WeekEnd&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Today&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;()),'YYYY/MM/DD')) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39);&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Actual and planned activity&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt; ActivityvPlan:&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;Load&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; *,&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Week Ending]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,'DD/MM/YYYY') &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;WeekEnding&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,&lt;BR /&gt; 'Past' &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;;&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;BR /&gt; SELECT&lt;BR /&gt; AP.[FinYear],&lt;BR /&gt; AP.[Month_Name],&lt;BR /&gt; AP.[Week Ending],&lt;BR /&gt; AP.[Site],&lt;BR /&gt; AP.[Activity Type] AS 'Activity Type (Original)',&lt;BR /&gt; CASE&lt;BR /&gt; WHEN AP.[Activity Type] = 'OP' THEN 'Outpatient'&lt;BR /&gt; WHEN AP.[Activity Type] = 'DayCase' THEN 'Day Case'&lt;BR /&gt; ELSE AP.[Activity Type] &lt;BR /&gt; END AS 'Activity Type',&lt;BR /&gt; UPPER(AP.[Specialty]) as [Specialty],&lt;BR /&gt; AP.[NC],&lt;BR /&gt; AP.[Plan],&lt;BR /&gt; CASE WHEN AP.[Week Ending] &amp;gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(@ActualWeekEndDate)&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; THEN 0 ELSE AP.[Actual] END AS 'Actual',&lt;BR /&gt; AP.[Actual] as 'RawActuals',&lt;BR /&gt; NULL as Booked,&lt;BR /&gt; GETDATE() AS 'Run Date',&lt;BR /&gt; 'Actual and Planned' AS 'Category'&lt;BR /&gt; --ISNULL(MSI.[Site],'Unknown') AS 'Site for Reporting'&lt;BR /&gt; FROM [BH_INFORMATION].[DBO].[PLAN_AND_ACTUAL] AS AP &lt;BR /&gt; LEFT JOIN [BH_INFORMATION].[dbo].[DivisionLookup] DL ON AP.Specialty = DL.SPECIALTY&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Link to site look-up table&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;LEFT OUTER JOIN [BH_PERFORMANCE].[dbo].[LKP_Site] AS LS&lt;BR /&gt; ON AP.[Site] = LS.[Raw Value]&lt;BR /&gt; AND LS.[Is Latest] = 'Y'&lt;BR /&gt; WHERE&lt;BR /&gt; AP.FinYear &amp;gt;= '2017/18'&lt;BR /&gt; AND AP.[Activity Type] &amp;lt;&amp;gt; 'Other';&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Future activity&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LET&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ExtractDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39)&amp;amp;'2017/09/15'&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39));&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//&lt;BR /&gt; //&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LET&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;@ActualWeekEndDate&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;WeekEnd&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Today&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;()),'YYYY/MM/DD')) &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Chr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(39);&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;CONCATENATE&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; (ActivityvPlan)&lt;BR /&gt; &lt;BR /&gt; FutureActivity:&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LOAD&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; *,&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Week Ending]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,'DD/MM/YYYY') &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;WeekEnding&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;,&lt;BR /&gt; 'Past' &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;;&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;SQL&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt; SELECT&lt;BR /&gt; F.[FinYear],&lt;BR /&gt; F.[Month_Name],&lt;BR /&gt; F.[Week Ending],&lt;BR /&gt; F.[Site],&lt;BR /&gt; F.[Activity Type] AS 'Activity Type (Original)',&lt;BR /&gt; CASE&lt;BR /&gt; WHEN F.[Activity Type] = 'Daycases' THEN 'Day Case'&lt;BR /&gt; WHEN F.[Activity Type] = 'Elective Inpatients' THEN 'Elective'&lt;BR /&gt; WHEN F.[Activity Type] IN ('First Outpatient Attendances','Outpatient procedures','Subsequent outpatient Attendances') THEN 'Outpatient'&lt;BR /&gt; ELSE 'Other' END AS 'Activity Type',&lt;BR /&gt; F.[Specialty],&lt;BR /&gt; DL.[DIVISION] AS Division,&lt;BR /&gt; NULL AS 'NC',&lt;BR /&gt; NULL AS 'Plan', &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Note: definitely do not use planned data in this future table as the planned fields are not correct in it&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;F.[Booked Activity] AS 'Actual',&lt;BR /&gt; F.Rundate&lt;/SPAN&gt;&lt;STRONG style=": ; color: #ff0000; font-size: 8pt;"&gt;)&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; AS 'Run Date',&lt;BR /&gt; 'Future Booked' AS 'Category',&lt;BR /&gt; ISNULL(MSI.[Site],'Unknown') AS 'Site for Reporting'&lt;BR /&gt; &lt;BR /&gt; FROM&lt;BR /&gt; [BH_INFORMATION].[DBO].[DASHBOARD_FUTURE] AS F&lt;BR /&gt; LEFT JOIN [BH_INFORMATION].[dbo].[DivisionLookup] DL ON F.Specialty = DL.SPECIALTY&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Link to site look-up table&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;LEFT OUTER JOIN [BH_PERFORMANCE].[dbo].[LKP_Site] AS LS&lt;BR /&gt; ON F.[Site] = LS.[Raw Value]&lt;BR /&gt; AND LS.[Is Latest] = 'Y'&lt;BR /&gt; &lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 8pt;"&gt;//--Link to master site table&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;LEFT OUTER JOIN&lt;BR /&gt; [BH_PERFORMANCE].[dbo].[Master_Site] AS MSI&lt;BR /&gt; ON LS.[Mapped Value] = MSI.[Site Original]&lt;BR /&gt; AND MSI.[Is Latest] = 'Y'&lt;BR /&gt; &lt;BR /&gt; WHERE&lt;BR /&gt; F.FinYear &amp;gt;= '2017/18'&lt;BR /&gt; AND CAST(F.Rundate AS DATE) = @ExtractDate&lt;BR /&gt; AND (CASE&lt;BR /&gt; WHEN F.[Activity Type] = 'Daycases' THEN 'Day Case'&lt;BR /&gt; WHEN F.[Activity Type] = 'Elective Inpatients' THEN 'Elective'&lt;BR /&gt; WHEN F.[Activity Type] IN ('First Outpatient Attendances','Outpatient procedures','Subsequent outpatient Attendances') THEN 'Outpatient'&lt;BR /&gt; ELSE 'Other' END) &amp;lt;&amp;gt; 'Other'; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 15:41:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399079#M812268</guid>
      <dc:creator>infock12</dc:creator>
      <dc:date>2017-09-22T15:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Union all plus variable</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399080#M812269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have fixed the above error but it is throwing out another error message: &lt;STRONG&gt;ErrorSource: Microsoft SQL Server Native Client 11.0, ErrorMsg: Must declare the scalar variable "@ExtractDate".&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 15:49:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399080#M812269</guid>
      <dc:creator>infock12</dc:creator>
      <dc:date>2017-09-22T15:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Union all plus variable</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399081#M812270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the second SQL statement, you use something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: 'Courier New'; font-size: 10.6667px;"&gt;AND CAST(F.Rundate AS DATE) = @ExtractDate&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Replace @ExtractDate with $(@ExtractDate) and try again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 16:02:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399081#M812270</guid>
      <dc:creator>Peter_Cammaert</dc:creator>
      <dc:date>2017-09-22T16:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Union all plus variable</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399082#M812271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Excellent, that worked like a charm Peter! Thank you very much and have a good weekend!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 16:21:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-Union-all-plus-variable/m-p/1399082#M812271</guid>
      <dc:creator>infock12</dc:creator>
      <dc:date>2017-09-22T16:21:23Z</dc:date>
    </item>
  </channel>
</rss>

