Variable Value in Top Statement

i want create a Procedure that behave like this:

declare @cnt int
set @cnt =10
select top @cnt * from sw_user

Where sw_user contains 20 records,
and i want the variable to be the criteria of Top statement.

so i can use this for a solution for this type of problem


CREATE PROC Top10
@cnt int AS
SET ROWCOUNT @cnt
SELECT * FROM sw_user

but some cases ROWCOUNT might not be work...

so what,


Note : This statement however is possible in SQL 2005, just add "()" in your variable like so:

declare @cnt int
set @cnt =10
select top (@cnt) * from sw_user

Comments

Popular posts from this blog

Auto Refresh .aspx page - ASP.NET

Auto Sequence Number in Grid Control with Paging

MVC Request Execution Stages - Life Cycle

Paged Data Source - Custom Paging

Overview of MVC

LINQ - C# Programming

ASP.NET MVC Version History

How to Edit More than 200 Rows in SQL Server 2008

LINQ to XML : XElement and XAttribute