title: Dynamic SQL Syntax Error SQLScript SAP HANA
body: <p>I have dynamic SQL in a Stored Procedure.</p>
  
  <p>The procedure takes three parameters:</p>
  
  <ul>
  <li>DimPartialName</li>
  <li>ColumnName</li>
  <li>UploadID</li>
  </ul>
  
  <p>Here is the procedure:</p>
  
  <pre><code>PROCEDURE "Schema"."DeletefromDIM" (In DimPartialName NVARCHAR(50), In 
  IDColumnName NVARCHAR(50), IN UploadID NVARCHAR(36) ) 
  LANGUAGE SQLSCRIPT
  SQL SECURITY INVOKER 
  --DEFAULT SCHEMA &lt;default_schema_name&gt;
  AS
  BEGIN
  EXECUTE IMMEDIATE
  'select distinct "'|| IDColumnName ||'" from 
  "Schema"."ZT.'|| DimPartialName ||'" dim
  LEFT JOIN "Schema"."SourceTable" raw on 
  dim."AUDIT.CREATED_ON" = raw."Audit.CREATED_ON"
  where "UPLOAD_UUID" = ' || UploadID ||' ';
  End;
  </code></pre>
  
  <p>And the Error:</p>
  
  <p>SAP DBTech JDBC: [257]: sql syntax error: "Schema"."DeletefromDIM": line 15 col 1 (at pos 520): [257] (range 3) sql syntax error exception: sql syntax error: incorrect syntax near "-": line 3 col 41 (at pos 214)</p>
  
  <p>when I run this SQL in the console and substitute in my inputs, then it works fine:</p>
  
  <pre><code>select distinct "BRANDID" from "Schema"."ZT.BRAND" dim
  LEFT JOIN "Schema"."SourceTable" raw on dim."AUDIT.CREATED_ON" = raw."Audit.CREATED_ON"
  where "UPLOAD_UUID" = 'f889e016-1364-4aac-9536-037d932c55b5'; 
  </code></pre>
  
  <p>The error doesn't really make sense because not only is there no "-" at that position, there is no dash in the entire statement.</p>