Use variable with TOP in select statement in SQL Server without making it dynamic?
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)?
Larry C.
answered 05/20/19
Computer Science and Mathematics professional
Have you tried something like
DECLARE @rowcutoff int
SET @rowcutoff = 5
SELECT * FROM sometable WHERE ROW_NUMBER <= @rowcutoff;
Still looking for help? Get the right answer, fast.
OR
Find an Online Tutor Now
Choose an expert and meet online.
No packages or subscriptions, pay only for the time you need.