在SSIS的Execute SQL Task组件中执行存储过程,想要返回单行的结果,总是无法返回查询的结果,返回的错误是无法把DBNull转换为String类型:
The type of the value (DBNull) being assigned to variable "User::MailBody" differs from the current variable type (String). Variables may not change type during execution. Variable types are strict, except for variables of type Object
对于这个错误,暂不做深入的调查。存储过程返回执行的结果,可以是通过返回值、基础表来实现,当然也可以通过output参数来实现。
在创建存储过程时,必须通过output关键字显式声明输出型参数。对于输出型参数,既可以接收值,也既可以不接收值,但是必须被赋值为变量,用于向外输出结果。没有用output关键字声明的参数是输入型参数,对于输入型参数,只接收值,不向外输出结果。
第一步:在存储过程中定义output参数 @para,声明输出型参数的格式如下所示:
@para data_type output
举个例子,创建一个存