检查您如何针对此示例使用它。
CREATE TYPE dbo.LineItem_TYPE AS TABLE
(
UnitTrade numeric (22,4),
TotalBuy numeric (22,4),
TotalSell numeric (22,4),
GrossProfit numeric (22,4),
QuoteReference varchar (255)
);
GO
CREATE TABLE LineItem
(
UnitTrade numeric (22,4),
TotalBuy numeric (22,4),
TotalSell numeric (22,4),
GrossProfit numeric (22,4),
QuoteReference varchar (255)
);
GO
create proc dbo.uspInsertLineItem
@li dbo.LineItem_TYPE READONLY
AS
set nocount on;
insert LineItem
select *
FROM @li;
GO
declare @li dbo.LineItem_TYPE;
insert @li select
1.23451234,123456789.1111,10.50,1,'Quote1' union all select
999999999999999999.9999,1.1,2.2,null,'Quote1';
exec dbo.uspInsertLineItem @li;
GO
select * from LineItem
------- results
UnitTrade TotalBuy TotalSell GrossProfit QuoteReference
------------------------ --------------- ---------- ------------ ---------------
1.2345 **** 123456789.1111 10.5000 1.0000 Quote1
999999999999999999.9999 1.1000 2.2000 NULL Quote1
您可以看到所有数字都忠实地存储到正确的小数位数,除了标有* * 的单数。我们1.23451234
输入@li,因为它是a numeric(22,4)
,一旦它进入用户类型,它就已经是1.2345。看到这个:
declare @li dbo.LineItem_TYPE;
insert @li (UnitTrade)
select 1.23451234;
select UnitTrade from @li
--------- result
UnitTrade
---------------------------------------
1.2345