我有一个存储过程,我在星期三工作得很好,但不再正常工作。我没有更改任何代码,并且由于某种原因它的行为方式不同。
这是不起作用的代码段:
WITH Minimum AS (SELECT DataTable.PortID, [Rating Max],
CASE When [Rating Max] <= [Sector Max] And [Rating Max] <= [ConcAfterUnwritten] And [Rating Max] <= [NatAfterUnwritten] And [Rating Max] <= [CashMaxAfterUnwritten] And [Rating Max] <= MatAfterUnwritten And [Rating Max] <= MatAfterInitialConcentration Then [Rating Max]
When [Sector Max] <= [ConcAfterUnwritten] And [Sector Max] <= [NatAfterUnwritten] And [Sector Max] <= CashMaxAfterUnwritten And [Sector Max] <= MatAfterUnwritten And [Sector Max] <= MatAfterInitialConcentration Then [Sector Max]
When ConcAfterUnwritten <= NatAfterUnwritten And ConcAfterUnwritten <= CashMaxAfterUnwritten And ConcAfterUnwritten <= MatAfterUnwritten And ConcAfterUnwritten <= MatAfterInitialConcentration Then ConcAfterUnwritten
When NatAfterUnwritten <= CashMaxAfterUnwritten And NatAfterUnwritten <= MatAfterUnwritten And NatAfterUnwritten <= MatAfterInitialConcentration Then NatAfterUnwritten
When CashMaxAfterUnwritten <= MatAfterUnwritten And CashMaxAfterUnwritten <= MatAfterInitialConcentration Then CashMaxAfterUnwritten
When MatAfterUnwritten <= MatAfterInitialConcentration Then MatAfterUnwritten
Else MatAfterInitialConcentration
End As [Min Of 5 Restrictions]
FROM DataTable)
UPDATE DataTable
Set
DataTable.MinOf5Restrictions = Minimum.[Min Of 5 Restrictions],
DataTable.MktValueAllocation = IIF(Minimum.[Min Of 5 Restrictions] < DataTable.MatAfterInitialConcentration, 0, DataTable.MatAfterInitialConcentration),
DataTable.ModelParAmount = IIf([MktValueAllocation]=0,0,Round([MktValueAllocation]/([$Px+Acc]*10)/5,0,1)*5),
DataTable.AllocatedPar = IIF(DataTable.ModelParAmount = 0, 0, ParLots.AllocatedPar),
DataTable.[Check Cash And Concentration] = IIf(DataTable.[AllocatedPar]*[$Px+Acc]*10>[MinOf5Restrictions],[ModelParAmount],DataTable.[AllocatedPar]),
DataTable.[Final After State Switch] = IIf([StateOnly]='TRUE',IIf([RestrictionType]='Specific',[Check Cash And Concentration],0),[Check Cash And Concentration])
FROM
((DataTable INNER JOIN Minimum ON DataTable.PortID = Minimum.PortID) LEFT JOIN ParLots ON DataTable.ModelParAmount = ParLots.ModelPar) INNER JOIN TestSet ON DataTable.PortID = TestSet.PortID, Main;
我目前的问题是我必须运行查询 6 次才能获得我想要的结果。基本上,UPDATE 语句似乎只在我每次执行它时更新其中一个列,而不是一次更新所有 6 个。第一次执行时 MinOf5Restrictions 已填充但其他列未填充,第二次填充 MktValueAllocation 但最后 4 列仍为空,等等。
知道为什么会这样吗?我想我可以将它分成 6 个不同的 UPDATE 语句,但如果我不必这样做,我宁愿不这样做,特别是因为我之前有它工作过。
谢谢