【问题标题】:Pass data for Readonly Data type when execute a SP in sql在 sql 中执行 SP 时传递只读数据类型的数据
【发布时间】:2020-12-14 06:51:08
【问题描述】:

我需要在 Sql Server 中执行一个 SP。我使用外部脚本执行 SP 如下。

Declare @partid int
Declare @Quantity float
Declare @unitCost float

Exec PRAMA.ins_parts @partid ,5,@Quantity ,@unitCost,'Adjusting balance' ,null 

在 PRAMA.ins_parts SP 中,

Create PROCEDURE [ins_parts]
      @part_id as int
    , @act as int
    , @qty as float
    , @cost as float
    , @comment as nvarchar(500)
    , @codes product_codes READONLY
    
AS
BEGIN
END

然后,当我执行上述查询并将数据传递给 SP 时,它会显示一条错误消息 “操作数类型冲突:NULL 与代码不兼容”

有没有办法解决这个问题?任何人都可以建议我一个解决方案吗?

【问题讨论】:

    标签: stored-procedures sql-update ssms readonly


    【解决方案1】:

    我找到了上述问题的解决方案。

    首先,您必须在查询中声明表类型参数,然后向其中插入数据。 在我的“product_codes”表中,它有 id (int) 和 code (varchar) 列。

     Declare @product_codes Parts_Product_Codes
        Declare @partid int
        Declare @Quantity float
        Declare @unitCost float
    
    Insert into @product_codes Values(null,null)
    
        Exec PRAMA.ins_parts @partid ,5,@Quantity ,@unitCost,'Adjusting balance' ,@product_codes
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-18
      • 1970-01-01
      • 2017-05-08
      • 1970-01-01
      • 2018-02-23
      • 1970-01-01
      • 2020-09-13
      • 1970-01-01
      相关资源
      最近更新 更多