SELECT @error_message vs SET @error_message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iitt2007
    New Member
    • Feb 2008
    • 13

    SELECT @error_message vs SET @error_message

    In my SP, I am using SELECT @error_message= 'string' . My collegue asked me to use SET@error_messa ge= 'string' ,
    I would like to know the differences for using SELECT vs SET.

    Here's the snippet of SP :

    set ANSI_NULLS ON
    set QUOTED_IDENTIFI ER ON
    GO

    ALTER PROCEDURE [dbo].[spd_name_of_sp]

    (

    @fileID Integer
    )
    as
    BEGIN
    SET NOCOUNT ON
    -- DECLARE variables AND SET default values:
    DECLARE @error int,
    @error_message varchar(400)

    SELECT @error = 0
    SELECT @error_message = ''

    -- Validate input parameters, AND apply default values as required:
    IF @fileID = 0
    BEGIN
    SELECT @error_message = 'ERROR : File ID must be supplied.'
    GOTO HANDLE_ERROR
    END

    DELETE FROM table
    WHERE drf_file_id = @fileID

    SELECT @error = @@ERROR
    IF @error <> 0 GOTO HANDLE_ERROR

    END_OF_PROC:
    GOTO EXIT_PROC

    HANDLE_ERROR:
    IF @error_message = ''
    BEGIN
    SELECT @error_message = spd_name_of_sto red_procedure failed'
    END

    -- Raise error passes control immediately to .NET calling application.
    RAISERROR(@erro r_message,16,1) WITH NOWAIT

    EXIT_PROC:
    END
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Here's a nice read.

    -- CK

    Comment

    • iitt2007
      New Member
      • Feb 2008
      • 13

      #3
      Nice article. Thanks CK.

      Comment

      • siva538
        New Member
        • Jun 2007
        • 44

        #4
        Really nice one. Thanks CK for posting this. A must read by every SQL guy.

        Comment

        Working...