SSMS:更新声明无效

时间:2016-09-29 09:47:48

标签: sql sql-server-2008

我有以下代码来更新表

    CREATE TABLE #TempDraft (Seq int IDENTITY(1,1) NOT NULL,RqItmID bigint,GoodID int,UnitID int,Qty int,Price money,Amount money,Discount money,Added money,SysDis money,SysAdd money,isGift bit)
        INSERT INTO #TempDraft(GoodID,RqItmID,UnitID,Qty,Price,Amount,Discount,Added,SysDis,SysAdd,isGift)
        SELECT GoodID,R.RqItmID,Unit_ID,OrderQty,P_Price,(OrderQty * P_Price),Discount,Added,0,0,0 FROM @Comparison C JOIN SLE.vw_ReqItmFull R on R.RqItmID

            DECLARE @DisPer decimal(6,2),@DisAmnt money

            SET @DisPer = (SELECT TOP 1 DisPer FROM @F_Itm)
            SET @DisAmnt = (SELECT TOP 1 DisAmnt FROM @F_Itm)

                        DECLARE @LastDis money,@LastQty decimal(16,2),@LastAdd money,@LastPrice money,@LastAmount money

                        SET @LastDis = (SELECT TOP 1 SysDis FROM #TempDraft WHERE RqItmID = @ActiveRII)
                        SET @LastAdd = (SELECT TOP 1 SysAdd FROM #TempDraft WHERE RqItmID = @ActiveRII)
                        SET @LastPrice = (SELECT TOP 1 Price FROM #TempDraft WHERE RqItmID = @ActiveRII)
                        SET @LastAmount = (SELECT TOP 1 Amount FROM #TempDraft WHERE RqItmID = @ActiveRII)


                        IF @DisPer >= 0 begin
                             /* SECTION 1 */
                            /* THIS STATEMENT DOESNT WORK vv */
                            UPDATE #TempDraft
                            SET SysDis = @DisPer
                            WHERE RqItmID = @ActiveRII
                            /* THIS STATEMENT DOESNT WORK ^^ */
                        end

                        IF @DisAmnt >= 0 begin
                         /* SECTION 2 */
                            UPDATE #TempDraft 
                            SET SysDis = @LastDis + @DisAmnt
                            WHERE RqItmID = @ActiveRII

                        end

现在问题是第1节不起作用。它不会更新任何表的任何部分。代码的其他部分正常工作,如果我从非工作部分中删除WHERE子句,它就可以工作。

然而,第2节与SECTION 1非常相似,而且两者中的WHERE子句是相同的,但不知何故SECTION 1没有更新,第2节工作正常。

我该怎么办?

感谢

0 个答案:

没有答案