.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

What is SQL to get the row number with Where clause

Posted By: Jai     Posted Date: September 25, 2008    Points:2   Category :Sql Server
Hi All,

I am using SQL Server 2005 Express. I am trying to get the row number with a condition. I wrote a stored procedure like this
=============================================================
Create PROCEDURE VendorTableRowNumber
-- Add the parameters for the stored procedure here
@VendorID int
AS
BEGIN
SELECT ROW_NUMBER() OVER(ORDER BY VendorID ASC) AS RowNumber,VendorID
FROM Vendors
WHERE VendorID= @VendorID
END
=============================================================

I have 6 rows and for any value of vendorID, I get the row number as 1. But if there is no Where Clause it gives the correct corresponding row numbers for all the 6 rows. What is the correct SQL for this

Thanks!

Responses
Author: Rahul             
Posted Date: February 08, 2009     Points: 5   

Try like this

SELECT * FROM ( select Title,created_date,Disptext,UserID,Category_Id cityid,isactive ROW_NUMBER() OVER (ORDER BY created_date desc) as row FROM tableName) a WHERE row > 10 and row <= 20



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend