概括
我正在尝试使用用户定义的表类型并从表值函数中返回它。
当前使用 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 将按预期解释它的方式声明它?
我究竟做错了什么?