Exit code

  • Hi,

    I am trying check if a files exists and if so continue with the procedure and if not exit out of the Procedure.

    the code I used below but it keeps erroring.

    Could any body help.

    DECLARE @isExists INT

    exec master.dbo.xp_fileexist @temp,

    @isExists OUTPUT

    SELECT case @isExists

    when 1 then 'Yes'

    else 'No'

    return

    end as

  • clucasi (6/9/2014)


    Hi,

    I am trying check if a files exists and if so continue with the procedure and if not exit out of the Procedure.

    the code I used below but it keeps erroring.

    Could any body help.

    DECLARE @isExists INT

    exec master.dbo.xp_fileexist @temp,

    @isExists OUTPUT

    SELECT case @isExists

    when 1 then 'Yes'

    else 'No'

    return

    end as

    Quick questions, what is the error message and where is the declaration for @temp?

    😎

  • set @temp= 'c:\xxx' + cast(@number as varchar(50)) + '.xml'

    DECLARE @isExists INT

    exec master.dbo.xp_fileexist @temp,

    @isExists OUTPUT

    SELECT case @isExists

    when 1 then 'Yes'

    return

    else 'No'

    end as isExists

    the error is Msg 156, Level 15, State 1, Line 39

    Incorrect syntax near the keyword 'return'.

  • You need to put your return statement in an IF, not in a SELECT. Example:

    IF @isExist = 'No'

    RETURN;

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

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