Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to use Parameter in select top query lke this

declare @Tot_10 int
select Top @Total FPG from Incentive_0_3_BD order by FPG
Posted

SQL
DECLARE @Total INT
SET @Total = 2
select Top (@Total) FPG from Incentive_0_3_BD order by FPG
 
Share this answer
 
Make it a dynamic query.

SQL
declare @mysql varchar(max)
declare @topCount varchar(4)
set @topCount='5'
set @mysql='select top ' + @topCount + '* from TABLE_NAME'

exec(@mysql)
 
Share this answer
 
You can't do it directly:
SQL
declare @Tot_10 int

DECLARE @myCommand NVARCHAR(1024)
SET @myCommand = 'select Top ' + CAST(@Tot_10 AS NVARCHAR) + 'FPG from Incentive_0_3_BD order by FPG'
EXECUTE (@myCommand)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900