I am trying to get around SQL's inability to use TOP with a variable. I am trying to select the TOP X and order by NEWID() to get X random records in a table. Any ideas?!
Thanks for the replies. I neglected to mention the SQL is actually going into an application. All I can write are static queries and not Dynamic SQL as what I write is a string to be used as a subquery.
I'd recommend converting the entire query into a stored proc. If that isn't an option your pretty much out of luck, unless you can have the app generate the query for you.
Denny
--Anything is possible. All it takes is a little research. (Me)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.