以下语句应将WAIR
表中的LSX_DC_SaleEvents
列更新为数值,但不会。它执行时没有错误但不更新我的表。
UPDATE LSX_DC_SaleEvents
SET WAIR = (SELECT WAIR = SUM(CurrentUPB*CurrentInterestRate) / SUM(CurrentUPB)
FROM LSX_DC_Loans
WHERE SaleEventID = 1)
WHERE SaleEventID = 1
内部选择的结果会返回值0.050993
,这是我想要在WAIR
表格的LSX_DC_SaleEvents
列中输入的内容,但它始终保持在{ {1}}即使下面的select语句返回正确的值。
0
任何人都可以抓住我做错的事吗?
SELECT WAIR = SUM(CurrentUPB*CurrentInterestRate) / SUM(CurrentUPB)
FROM LSX_DC_Loans
列的数据类型为WAIR
,这对我的目的来说很好,我不需要浮动可以干扰吗?
答案 0 :(得分:1)
由于您的数据类型,可能会导致结果四舍五入。
试试这个,
UPDATE LSX_DC_SaleEvents
SET
WAIR =
(
SELECT WAIR = SUM(CAST(CurrentUPB AS DECIMAL(19, 6)) * CAST(CurrentInterestRate AS DECIMAL(19, 6))) / SUM(CAST(CurrentUPB AS DECIMAL(19, 6)))
FROM LSX_DC_Loans
WHERE SaleEventID = 1
)
WHERE SaleEventID = 1;
答案 1 :(得分:0)
UPDATE LSX_DC_SaleEvents
SET WAIR = CHAR((SELECT (SUM(CurrentUPB*CurrentInterestRate) / SUM(CurrentUPB)) * 1.0000
FROM LSX_DC_Loans
WHERE SaleEventID = 1), 8)
WHERE SaleEventID = 1
为什么不这样做呢?为什么你有" WAIR ="在子查询?