0

I have a stored procedure. In SQL SERVER

ALTER PROCEDURE [dbo].[Test] 
    @Test
AS
BEGIN
    // Inside It, I am calling another SP with OUTPUT PARAM
  exec B
    @ErrorCode = @error output


-- SP B Will Return error if there is any in the logic

-- HERE I am checking 

IF(@error>0)
        UPDATE [dbo].[C] 
        SET IS_DELETED = 0,
        WHERE Id = 7

END

Is there any possibility that the update statement happens before @error is set ?

user123456
  • 2,524
  • 7
  • 30
  • 57
  • Which dbms are you using? (Perhaps SQLServer?) – jarlh Feb 28 '19 at 09:20
  • I believe your IF is supposed to be inside the Test SP (it's currently outside the BEGIN/END). Or the IF is the B SP? – EzLo Feb 28 '19 at 09:21
  • You do not regain control until the inner stored procedure has completely finished executing. If you've got some unexplained behaviour, perhaps ask a direct question about that? – Damien_The_Unbeliever Feb 28 '19 at 09:21
  • @Damien_The_Unbeliever I got some unexplained behaviour. – user123456 Feb 28 '19 at 09:23
  • @EzLo YOu are right. – user123456 Feb 28 '19 at 09:24
  • 3
    Right, so change your question. You've got some unexplained behaviour. You thought one possible explanation could be if the code after `EXEC` can execute before that `EXEC` has finished. It cannot. So, tell us *what you expected to happen* and *what you're observing*. – Damien_The_Unbeliever Feb 28 '19 at 09:27
  • No Way the if condition logic gets executed before that EXE ? – user123456 Feb 28 '19 at 09:33
  • Can I Put wait statement ? https://stackoverflow.com/questions/7676164/how-to-wait-for-2-seconds – user123456 Feb 28 '19 at 09:35
  • NO. I've said as much twice already in the comments. Whatever's happening, it's *not that*. We can't help you though if you keep saying "it must be that" and seeking confirmation. – Damien_The_Unbeliever Feb 28 '19 at 09:50
  • OK. @Damien_The_Unbeliever Is there any way in which I can get all the queries executed against row, I am doubting somebody accessed the database and changed the value. – user123456 Feb 28 '19 at 11:19

0 Answers0