I have the following script in a Execute SQL Task Editor. I have two parameters that I have mapped to the question marks. The query parses when I set @ClientCode and @PEK to something else. Why does my query not parse with the ? parameters? The full error is "The query failed to parse. Syntax error, permission violation, or other nonspecific error"
declare @ClientCode varchar(100)
declare @PEK int
set @ClientCode = ?
set @PEK = ?
if((@ClientCode != '') and (@ClientCode is not null))
begin
exec portal.GetClients @ClientCode
end
else if((@PEK != 0) and (@PEK != '' ))
begin
select distinct c.Id, c.Name, c.Code
from Features.map.ProfileAreasManagementAreas pama INNER JOIN
ClientDW.dbo.ManagementAreas ma ON pama.ManagementAreaKey = ma.ManagementAreaKey INNER JOIN
ClientDW.dbo.Clients c ON ma.ClientKey = c.ClientKey
where pama.PublishEventKey = @PEK
end
else
begin
select top 1 PublishEventKey
from Features.publish.PublishEvents
order by PublishDate desc
end

Something must be awry with how you have things configured or the code has been sanitized.
I built a reproduction package and have it configured thusly

Parameters make no difference whether I specify -1 lengths or 100 and 0 as one might expect for varchar(100) and int.

Runs successfully

The SQL I used was simplified to
declare @ClientCode varchar(100)
declare @PEK int
set @ClientCode = ?
set @PEK = ?
I find it helpful to distill problems down to their essentials. If this logic and parameter assignment work, then there's something wrong with the rest of the TSQL.
Since that all worked, I then modified your TSQL to be
declare @ClientCode varchar(100)
declare @PEK int
set @ClientCode = ?
set @PEK = ?
if((@ClientCode != '') and (@ClientCode is not null))
begin
PRINT @ClientCode;
end
else if((@PEK != 0) and (@PEK != '' ))
begin
PRINT @PEK;
end
else
begin
PRINT CURRENT_TIMESTAMP;
end
I tested with '' and 0 which printed current date and time. I then gave PEK a non-zero value and it echoed the non-zero value back. Finally, I gave the client code a non-empty string and it too was shown so the logic all seems to be in order.
I used the following Biml to generate a prototype package. You can use either the free tool BIDSHelper or Biml Express to take Biml files and make SSIS packages - it's very cool.
After installing either tool, right click on the SSIS project and select Add new Biml file. Copy and paste the following code into the BimlScript.biml file.
Edit the third line (OleDbConnection ) to point the ConnectionString's DataSource to a valid database server in your world.
Save.
Right click on the BimlScript.biml file and select Generate SSIS Packages.
Magic, you now have a replica of what works. Try using that to patch in your pieces and test against that.
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<OleDbConnection Name="tempdb" ConnectionString="Data Source=localhost\dev2014;Initial Catalog=tempdb;Provider=SQLNCLI11.0;Integrated Security=SSPI;"/>
</Connections>
<Packages>
<Package Name="so_37932933">
<Variables>
<Variable DataType="Int32" Name="PublishEventKey">0</Variable>
<Variable DataType="String" Name="ClientCode">mixed</Variable>
</Variables>
<Tasks>
<ExecuteSQL ConnectionName="tempdb" Name="SQL Parameter test">
<DirectInput><![CDATA[declare @ClientCode varchar(100)
declare @PEK int
set @ClientCode = ?
set @PEK = ?]]></DirectInput>
<Parameters>
<Parameter DataType="AnsiString" VariableName="User.ClientCode" Name="0" Length="100" />
<Parameter DataType="Int32" VariableName="User.PublishEventKey" Name="1" />
</Parameters>
</ExecuteSQL>
</Tasks>
</Package>
</Packages>
</Biml>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With