patternsqlModerate
Select TOP @N where @N is a variable from another Query
Viewed 0 times
topwherequeryanotherselectfromvariable
Problem
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
I need to now do this...
How do I do this correctly?
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?
Solution
You need to enclose the variable in parenthesis:
MSDN Reference on
select top (@OtherHDDs) -- your column list here
from YourTableMSDN Reference on
SELECTCode Snippets
select top (@OtherHDDs) -- your column list here
from YourTableContext
StackExchange Database Administrators Q#21838, answer score: 12
Revisions (0)
No revisions yet.