我想将一些数据存储到SQL Server中的表类型中。在下面的代码中,我定义了表的结构并将其声明为类型。但后来,使用该类型声明的变量无法找到它。错误是:
列,参数或变量#17:找不到数据类型ARTSRetailPriceModifier。
声明的代码和变量的赋值是:
CREATE TYPE ARTSRetailPriceModifier AS TABLE
(
ID int NOT NULL IDENTITY(1,1),
RecID int,
PromoId int,
SNumber int,
MCode VARCHAR(50),
Amount DECIMAL(7,2),
[Action] VARCHAR(20),
NPrice DECIMAL(7,2),
PPrice DECIMAL(7,2),
RCode VARCHAR(1),
PCondition VARCHAR(1)
);
DECLARE @PriceModifiers AS ARTSRetailPriceModifier
INSERT INTO @PriceModifiers (
RecID,
PromoId,
SNumber,
MdCode,
Amount,
[Action],
NPrice,
PPrice,
RCode,
PCondition
)
SELECT d.RecID AS 'RecID'
, 1 AS 'PromotionID'
, d.SequenceNumber + 1 AS 'SequenceNumber'
, 'PriceOverride'AS 'MethodCode'
, ABS(d.RetailPrice - d.UnitListPrice) AS 'Amount'
, 'Replace' AS 'Action'
, d.UnitListPrice AS 'NewPrice'
, d.RetailPrice AS 'PreviousPrice'
, '1' AS 'ReasonCode'
, '1' AS 'PromoCondition'
FROM #Items d
表格#Items
已正确填写。
答案 0 :(得分:0)
在GO
之后添加CREATE TYPE
。
请参阅示例here。
可能的解释是,在事务完成之前,类型没有构造或添加到系统中,但是当我们要用它执行某些操作时,我们必须在系统中有一个真实的类型。