Exforsys

Online Training

Row count in sqlserver

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


Go Back   Exforsys > Articles and Tutorials > SQL Server 2005 Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-05-2004, 05:56 PM
Junior Member
 
Join Date: Jun 2004
Posts: 12
Pramodm
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-05-2004, 09:04 PM
Senior Member
 
Join Date: Nov 2004
Posts: 177
sanereddy is an unknown quantity at this point
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-15-2004, 01:23 PM
Junior Member
 
Join Date: Oct 2004
Posts: 1
Manohargmr
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:27 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.