是表类型时必须声明标量变量@bundleTransfer吗?

时间:2018-11-07 22:03:00

标签: sql-server-2008 sqldatatypes user-defined-types ssms-2017

  

摘要

我正在尝试使用用户定义的表类型,并从表值函数返回它。

当前使用SQL Server 2008及其XML查询。

  

样品

create type udtBundleTransferTableType table as (
    C_PPPI_BATCH              varchar(10)   not null,
    C_PPPI_SO_ISSUE           varchar(10)   not null,
    C_PPPI_SO_RECEIPT         varchar(10)   not null,
    C_PPPI_MATERIAL           varchar(18)   not null,
    C_PPPI_MATERIAL_CONSUMED  decimal(11,4) not null,
    [TIMESTAMP]               datetime      not null default getDate()
)
go

create function dbo.udfReadBundleTransferInformationReceived(@bundleTransferMessage xml)
    returns udtBundleTransferTableType as
begin
    declare @bundleTransferInformation udtBundleTransferTableType
    insert into @bundleTranserInformation(C_PPPI_BATCH
                                        , C_PPPI_SO_ISSUE
                                        , C_PPPI_SO_RECEIPT
                                        , C_PPPI_MATERIAL
                                        , C_PPPI_MATERIAL_CONSUMED)
        select bundle.transfer.value('C_PPPI_BATCH[1]', 'varchar(10)') as C_PPPI_BATCH
                , bundle.transfer.value('C_PPPI_SO_ISSUE[1]', 'varchar(10)') as C_PPPI_SO_ISSUE
                , bundle.transfer.value('C_PPPI_SO_RECEIPT[1]', 'varchar(10)') as C_PPPI_SO_RECEIPT
                , bundle.transfer.value('C_PPPI_MATERIAL[1]', 'varchar(18)') as C_PPPI_MATERIAL
                , bundle.transfer.value('C_PPPI_MATERIAL_CONSUMED[1]', 'decimal(11,4)') as C_PPPI_MATERIAL_CONSUMED
                , bundle.transfer.value('TIMESTAMP[1]', 'datetime') as [TIMESTAMP]
            from @bundleTransferMessage.nodes('/BundleTransferMessage/Characteristics') bundle(transfer)

    return @bundleTransferInformation
end
  

错误

Msg 137, Level 16, State 1, Procedure udfReadBundleTransferInformationReceived, Line 35 [Batch Start Line 0] Must declare the scalar variable @bundleTransferInformation

  

问题

What's happening?

我不明白为什么SSMS说我必须声明标量变量,因为它不是标量变量,而是表变量!

如何以SSMS / SQL Server能够按预期解释它的方式声明它?

我在做什么错了?

0 个答案:

没有答案