Count the number of rows in a UNION ALL statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • markjerz@googlemail.com

    Count the number of rows in a UNION ALL statement

    Hi,

    Should be quite simple but can someone please tell me the best way to
    count the number of rows in an UNION ALL statement.

    I tried using @@ROWCOUNT but that doesn't seem to contain the correct
    number.

    Also, I assume that running the query again but just returning count(*)
    instead of the data is horribly inefficient (plus the code is then
    bloated.)?

    Thanks,
    Mark

  • Marcin A. Guzowski

    #2
    Re: Count the number of rows in a UNION ALL statement

    markjerz@google mail.com wrote:
    Hi,
    >
    Should be quite simple but can someone please tell me the best way to
    count the number of rows in an UNION ALL statement.
    >
    I tried using @@ROWCOUNT but that doesn't seem to contain the correct
    number.
    Why do you think so? Can you provide an example of a query with
    incorrect @@ROWCOUNT value returned? What's the version of SQL Server?


    --
    Best regards,
    Marcin Guzowski

    Comment

    Working...