Stored Procedure Error

  • Hi

    I am creating stored procedure for the first time.  I am getting error:

    Msg 207, Level 16, State 1, Procedure CHECK_IMPORT_HISTORY, Line 9 [Batch Start Line 0]

    Invalid column name 'NUM_RECORDS'.

    Completion time: 2022-01-28T21:42:14.6129465-08:00

    I even changed the name to NUM_RECORDS_1 in the output parameter and no luck with the error.

    What is wrong with my query?

    Thank you

    CREATE PROCEDURE CHECK_IMPORT_HISTORY (@FILENAME VARCHAR(100), @NUM_RECORDS INT OUTPUT)
    AS
    BEGIN

    SELECT COUNT(*) AS NUM_RECORDS
    FROM DBO.DataImportFileImportHistory AS T1
    WHERE T1.FILENAME LIKE @FILENAME;

    SELECT @NUM_RECORDS = NUM_RECORDS;

    END

    • This topic was modified 2 years, 2 months ago by  water490.
    • This topic was modified 2 years, 2 months ago by  water490.
  • You need to include your variable assignment in the query

    SELECT @NUM_RECORDS = COUNT(*)
    FROM DBO.DataImportFileImportHistory AS T1
    WHERE T1.FILENAME = @FILENAME;
  • Thank you so much!  It works as planned.

  • This was removed by the editor as SPAM

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

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