2017-10-13 61 views
0

我下面的代碼,但它給出了一個錯誤,請指導我如何嵌套if..begin..begin__tran__Rollback或承諾If..begin..begin tran..Rollback

declare @acname as varchar(max), 
    @gstcount as int 

set @acname='Party1' 

use TESTDB 

set @gstcount = (select count(GSTIN) from M_STATEWISEGSTINACTAG where GSTIN<>'UNREGISTERED' AND ACCD= 
(select accd from m_ledger where descr LIKE @acname)) 


if @gstcount = 1 
    begin 
    --multiple select statments 
    select ....... 
    --to display require info. 
    end 

--Then Update Values 
    begin tran; 
     update M_tbl ........where.... 

    --Show result with updated value 
     select * from M_tbl........where......... 

    --Undo Changes 
     ROLLBACK; 
else 
begin 
     SELECT ........reuqir info 

end; 

在此腳本我得到一個錯誤'關鍵字'else'附近的語法不正確。

+0

我檢查與終端,終端;,年底陳德良,結束TRAN;它仍然給我一個相同的行號錯誤 –

回答

0

試試這個:

DECLARE @acname AS VARCHAR(MAX), @gstcount AS INT; 
SET @acname = 'Party1'; 
USE TESTDB; 
SET @gstcount = 
(
    SELECT COUNT(GSTIN) 
    FROM M_STATEWISEGSTINACTAG 
    WHERE GSTIN <> 'UNREGISTERED' AND ACCD =(SELECT accd FROM m_ledger WHERE descr LIKE @acname) 
); 
IF @gstcount = 1 
    BEGIN 
     BEGIN 
    --multiple select statments 

      SELECT ....... 
    --to display require info. 
     END; 

--Then Update Values 
     BEGIN TRAN; 
      update M_tbl ........where.... 
    --Show result with updated value 
      select * from M_tbl........where......... 
    --Undo Changes 
     ROLLBACK TRAN; 
    END; 
    ELSE 
    BEGIN 
     SELECT........reuqir info; 
    END; 
相關問題