Exforsys
+ Reply to Thread
Results 1 to 3 of 3

Row count in sqlserver

This is a discussion on Row count in sqlserver within the SQL Server forums, part of the Database category; Hello, How we can find the rowcount in sqlserver. I have 10 rows displayed, I want to get numbering for ...

  1. #1
    Pramodm is offline Junior Member Array
    Join Date
    Jun 2004
    Answers
    8

    Row count in sqlserver

    Hello,

    How we can find the rowcount in sqlserver. I have 10 rows displayed, I want to get numbering for the rows.ie 1 to 10. Please clarify it.

    Regards
    Pramod

    Post edited by: pramodm, at: 2004/11/05 16:56


  2. #2
    sanereddy is offline Member Array
    Join Date
    Nov 2004
    Answers
    85

    Re:Row count in sqlserver

    Returns the number of rows affected by the last statement.

    Syntax
    @@ROWCOUNT

    Return Types
    integer

    Remarks
    This variable is set to 0 by any statement that does not return rows, such as an IF statement.

    this is how it works...

    UPDATE authors SET au_lname = \'Jones\'
    WHERE au_id = \'999-888-7777\'
    IF @@ROWCOUNT = 0
    print \'Warning: No rows were updated\'

    here is another way of using it ..

    You can use the SET ROWCOUNT statement or the TOP clause of the select statement (there is no TOP clause in SQL Server 6.5).
    There are examples to return only the 10 top rows from the authors table in the pubs database:

    SET ROWCOUNT 10
    GO
    SELECT * FROM pubs.dbo.authors
    GO

    or

    SELECT TOP 10 * FROM pubs.dbo.authors


    for displaying the number for each record, I don\'t see any reason why would you wan to do, there are many different efficiant ways for this.

    Post edited by: sanereddy, at: 2004/11/05 20:12


  3. #3
    Manohargmr is offline Junior Member Array
    Join Date
    Oct 2004
    Answers
    1

    Re:Row count in sqlserver

    --To Print the row number from 1 to 10(or any Number).

    select (select count(*)+1 from employee where emp_id <s.emp_id) \'SNO\', * from employee s
    ORDER BY emp_id


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...