Query ,executed if it ok , move next query

Posted by Raja_89 under Sql Server on 8/18/2015 | Points: 10 | Views : 380 | Status : [Member] | Replies : 2
Hai
I am using sql stored procedure.sql server 2008 R2
Is it possible to check above query is executed is fine or not
if it fine move to next query

If there is any it will refiect in c#
How can i proceed

Example

insert into a(f1,f2,f3)values(a1,b1,c1)
if the above query sucessfull execution
it will go to update
update b set f4=@f4 where f1=2






Responses

Posted by: Sheonarayan on: 8/18/2015 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
When you write multiple statement in stored procedure, by default the execution process begins from top to bottom. Means if above query is successful then following line executes otherwise it throws error.

If you have some special scenario where you want to check for the error, use @@Error value and then execute next query.

Read https://msdn.microsoft.com/en-IN/library/ms188790.aspx (2nd code snippet)

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/19/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
insert into a(f1,f2,f3)values(a1,b1,c1) 

IF @@ERROR <>0 -- if any error doesn't occur
BEGIN
update b set f4=@f4 where f1=2
END
/CODE]

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response