What function in SQL Server works like rownum in Oracle?

Q:  I want to get the no. of fridays with their dates in one sql query. In oracle if we use rownum we can solve the same. Can u tell me how to do that in a single query in sql server? Is there any function in sql server?

Trent Mera says:    The SQL grouping functions (GROUP BY, CUBE, ROLLUP) would show you in a single query the number of rows matching various criteria, but would not show you the individual date values as you mentioned.

Selecting the @@ROWCOUNT variable in a second query is the easiest way to do what you’re asking:

SELECT OrderDate
FROM Northwind.dbo.Orders
WHERE DATENAME(weekday, OrderDate) = ‘Friday’

SELECT @@ROWCOUNT

Technorati Tags:
, ,

Tags:

Leave a Reply