need update statement that does nothing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jay123
    New Member
    • Sep 2008
    • 121

    need update statement that does nothing

    hi all,
    i m struck with very pericular problem. my problem is i have store proc as

    Code:
    ALTER PROCEDURE [dbo].[up_ActionSave]
    (@RowID  UniqueIdentifier,
     @ID  int,
     @Type Varchar(100),
     
    )
    AS
    SET NOCOUNT ON
    
    begin
       
        if exists(select X09ID from E09ACTION where (X09ID=@ID) AND (X09TYPE=@Type) AND (X09PROCESSED=NULL))
    	begin
    		//do nothing
    	end
    else if exists(select X09ROW from E09ACTION where X09ROW=@RowID)
    	begin
    		update E09ACTION set
    			X09ID=@Id,
    			X09TYPE=@TYPE,
    								
    		where X09ROW = @RowID
    	end
    end
    now what i want if first condition is meet then nothing should happen, can anybody suggest that what i could write in
    Code:
    // do nothing line
    .

    any help with code will be appreciated..

    nb: i have deleted some rows and coloumn from table just to make the sp shorter here, so thats not a prob
  • gpl
    New Member
    • Jul 2007
    • 152

    #2
    Originally posted by jay123
    hi all,
    i m struck with very pericular problem. my problem is i have store proc as

    ............... .......

    now what i want if first condition is meet then nothing should happen, can anybody suggest that what i could write in
    Code:
    // do nothing line
    .

    any help with code will be appreciated..

    nb: i have deleted some rows and coloumn from table just to make the sp shorter here, so thats not a prob

    The answer here is to reverse the sense of your first condition so that you do not need an else:
    Code:
    /* Powered by General SQL Parser (www.sqlparser.com) */
    
    ALTER PROCEDURE [dbo].[up_ActionSave]
    (@RowID  UniqueIdentifier,
     @ID  int,
     @Type Varchar(100),
     
    )
    AS
    Set Nocount On
    
     Begin
    
      If Not Exists (Select X09id
                     From   E09action
                     Where  (X09id = @ID)
                            And (X09type = @Type)
                            And (X09processed = Null))
        Begin
          If Exists (Select X09row
                     From   E09action
                     Where  X09row = @RowID)
            Begin
              update E09ACTION set
              			X09ID=@Id,
              			X09TYPE=@TYPE			
              		where X09ROW = @RowID
            End
        End
    End
    I used the very useful reformatter shown in the top line to layout the code neatly !!
    Graham

    Comment

    Working...