Setting Variable to Reflect Number of Records Found

  • I'm trying to set a variable to indicate how many records are going to be updated by a procedure.

    If I try (simple example)

    SET @COUNT = Select count(*) from tablename where last_name = 'Brown'

    the system doesn't like it.

    What would be the correct approach to set this variable?

    Thank you.

    Roger

  • try

    select @COUNT = count(*) from tablename where last_name = 'Brown'



    Clear Sky SQL
    My Blog[/url]

  • what you can also do, if what you actually care about is the number of records that *were* updated, rather than the number of records that *will* be updated, is set a variable to @@rowcount, which is the SQL statement that shows the number of records updated/deleted.

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

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