sql - SSIS 执行 SQL 任务编辑器查询解析失败

标签 sql ssis

我在执行 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 

image of Parameter Mapping

最佳答案

您的配置方式或代码已清理的方式一定有问题。

我构建了一个复制包并对其进行了配置

enter image description here

对于 varchar(100) 和 int,无论我指定 -1 长度还是指定 100 和 0,参数都没有区别。

enter image description here

运行成功

enter image description here

我使用的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 生成了一个原型(prototype)包。您可以使用免费工具 BIDSHelperBiml Express获取 Biml 文件并制作 SSIS 包 - 这非常酷。

安装任一工具后,右键单击 SSIS 项目并选择添加新的 Biml 文件。将以下代码复制并粘贴到 BimlScript.biml 文件中。

编辑第三行 (OleDbConnection) 以将 ConnectionStringDataSource 指向您所在世界的有效数据库服务器。

保存。

右键单击 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>

关于sql - SSIS 执行 SQL 任务编辑器查询解析失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37932933/

相关文章:

sql - 查询的意义是什么?

azure - 如何将 ssis 原始文件转换为 Parquet

excel - SSIS Excel 目标空白

sql-server - 从存储过程执行 SQL Server SSIS 包

sql - 星型架构设计/最佳实践

PHP 变量未显示在页面上

mysql - 来自 MySQL 的不一致查询结果

sql - FoxPro 中的限制

sql - 我应该如何从 SSIS 包执行以 varchar(max) 形式存储在表中的 sql 脚本?

sql-server - 外部列与输出列之间有什么区别?