0 votes
1 view
in SQL by (20.3k points)

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)?

1 Answer

0 votes
by (40.3k points)

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...