By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,766 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,766 IT Pros & Developers. It's quick & easy.

need update statement that does nothing

100+
P: 121
hi all,
i m struck with very pericular problem. my problem is i have store proc as

Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[up_ActionSave]
  2. (@RowID  UniqueIdentifier,
  3.  @ID  int,
  4.  @Type Varchar(100),
  5.  
  6. )
  7. AS
  8. SET NOCOUNT ON
  9.  
  10. begin
  11.  
  12.     if exists(select X09ID from E09ACTION where (X09ID=@ID) AND (X09TYPE=@Type) AND (X09PROCESSED=NULL))
  13.     begin
  14.         //do nothing
  15.     end
  16. else if exists(select X09ROW from E09ACTION where X09ROW=@RowID)
  17.     begin
  18.         update E09ACTION set
  19.             X09ID=@Id,
  20.             X09TYPE=@TYPE,
  21.  
  22.         where X09ROW = @RowID
  23.     end
  24. end
now what i want if first condition is meet then nothing should happen, can anybody suggest that what i could write in
Expand|Select|Wrap|Line Numbers
  1. // 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
Nov 7 '08 #1
Share this Question
Share on Google+
1 Reply


100+
P: 152
gpl
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
Expand|Select|Wrap|Line Numbers
  1. // 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:
Expand|Select|Wrap|Line Numbers
  1. /* Powered by General SQL Parser (www.sqlparser.com) */
  2.  
  3. ALTER PROCEDURE [dbo].[up_ActionSave]
  4. (@RowID  UniqueIdentifier,
  5.  @ID  int,
  6.  @Type Varchar(100),
  7.  
  8. )
  9. AS
  10. Set Nocount On
  11.  
  12.  Begin
  13.  
  14.   If Not Exists (Select X09id
  15.                  From   E09action
  16.                  Where  (X09id = @ID)
  17.                         And (X09type = @Type)
  18.                         And (X09processed = Null))
  19.     Begin
  20.       If Exists (Select X09row
  21.                  From   E09action
  22.                  Where  X09row = @RowID)
  23.         Begin
  24.           update E09ACTION set
  25.                       X09ID=@Id,
  26.                       X09TYPE=@TYPE            
  27.                   where X09ROW = @RowID
  28.         End
  29.     End
  30. End
I used the very useful reformatter shown in the top line to layout the code neatly !!
Graham
Nov 10 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.