Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am building a report on server hardware projections, and I'm getting stuck here.

I have a query that correctly returns the number of HDD's installed on the server, and am storing that number into a variable called @OtherHDDs, and it is an INT.

I need to now do this...

Select top @OtherHDDs.... 
from ...

How do I do this correctly?

share|improve this question
up vote 11 down vote accepted

You need to enclose the variable in parenthesis:

select top (@OtherHDDs) -- your column list here
from YourTable

MSDN Reference on SELECT

share|improve this answer
Thank you, this was the first thing I tried but I assumed it was wrong when it didn't work, turns out I just had some wonky settings in my report building tool. – Hoser Aug 1 '12 at 19:18
No problem, glad to help. – Thomas Stringer Aug 1 '12 at 19:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.