IF ROW COUNT = 0 GO TO END

  • Hello,

    I need to add a step in my stored procedure at the very beginning where it checks if TABLE A has any records or is blank before moving down the code of the stored proc.
    i.e.
    IF (SELECT ROW COUNT(*) FROM TABLE A) > 0
    THEN
         BEGIN
                 DROP INDEX....
                  DELETE FROM TABLE B......
                 INSERT INTO TABLE B......
                  RE-CREATE INDEX.....
       END
    ELSE
      ???????????????????????????????

    Here's where I'm not sure what the syntax/command/function needs to be in order to tell it to just go to the end of the stored proc if the row count in TABLE A = 0.

  • if not exists (select 1 from TableA)
      return;

    Should exit the proc at that point, if zero rows are found.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin - Wednesday, July 11, 2018 6:56 AM

    if not exists (select 1 from TableA)
      return;

    Should exit the proc at that point, if zero rows are found.

    That worked just fine. Thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply