Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 8 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
add comment

Your Answer

 
discard

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.