[英]SSIS Execute SQL Task Editor query failed to parse
我在“执行SQL任务编辑器”中具有以下脚本。 我有两个映射到问号的参数。 当我将@ClientCode和@PEK设置为其他值时,查询将解析。 为什么我的查询不解析? 参数? 完整错误为“查询解析失败。语法错误,权限冲突或其他非特定错误”
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
必须对配置的方式或对代码进行过清理的方式有所了解。
我构建了一个复制包,并对其进行了配置
无论我指定-1长度还是100和0(因为varchar(100)和int可能会这样),参数都没有区别。
运行成功
我使用的SQL简化为
declare @ClientCode varchar(100)
declare @PEK int
set @ClientCode = ?
set @PEK = ?
我发现将问题精简到本质是有帮助的。 如果此逻辑和参数分配有效,则TSQL的其余部分有问题。
既然一切正常,然后我将您的TSQL修改为
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
我用''和0测试了当前日期和时间。 然后,我给PEK一个非零值,它回显了非零值。 最后,我为客户代码提供了一个非空字符串,并且也显示了该字符串,因此逻辑似乎都井井有条。
我使用以下Biml生成了原型包。 您可以使用免费工具BIDSHelper或Biml Express来获取Biml文件并制作SSIS软件包-这非常酷。
安装任何一种工具后,右键单击SSIS项目,然后选择“添加新Biml文件”。 将以下代码复制并粘贴到BimlScript.biml文件中。
编辑第三行(OleDbConnection),将ConnectionString
的DataSource
指向您所在世界中的有效数据库服务器。
救。
右键单击BimlScript.biml文件,然后选择“生成SSIS包”。
魔术,您现在拥有了一个可行的复制品。 尝试使用它修补您的作品并进行测试。
<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>
我看到的解决方案如下。 当我测试真实数字时,我尝试使用@ClientCode的空字符串,并且绕过了exec门户.GetClients存储了proc。 事实证明,我对此没有执行要求。 其次,将BypassPrepare设置为false,并且由于某些原因? 查询中的参数不准备添加参数的查询。 因此,当我再次将BypassPrepare设置为true时,不必担心解析查询并只执行了工作正常的任务(对查询具有新的执行权限)。 谢谢那些试图回答它的人。 我认为这是正确的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.