Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql top N value

How can I make a SQL query and have a parameter the top N value. For example the first person wants to see the top 10 values, the next perhaps the top 50, maybe the top 100. Would I say something like SELECT TOP =@Value from Table?

Thanks

Yes this is for SQL Server. Standard Query, showing everything, but id like to limit the number of rows returned based on input from the user.

like image 801
GabrielVa Avatar asked Feb 16 '26 20:02

GabrielVa


1 Answers

SELECT TOP(cast(@N as integer)) COLUMN1 ,Column2 from table1

That works...

like image 73
GabrielVa Avatar answered Feb 19 '26 01:02

GabrielVa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!