declare @top intset @top = 5select top @top * from tablename
declare @top int
set @top = 5
select top @top * from tablename
Is it possible?
Or any idea for such a logic (i don't want to use dynamic query)?
Yes, it is possible to use the variable with TOP in select statement in SQL Server without making it dynamic.
In SQL Server 2005, you can use a variable in the top clause in this way:
select top (@top) * from tablename