November 1, 2007 at 3:30 pm
Hello guys,
Is there a way to declare TOP? something like this:
DECLARE @Rows int
SET @Rows = 100
select top @Rows Fname, Lname, Addr1, Addr2, City, State, Zip, phone from tblname
Thanks
November 1, 2007 at 3:33 pm
SET ROWCOUNT
_____________
Code for TallyGenerator
November 1, 2007 at 3:43 pm
thanks...
November 1, 2007 at 4:52 pm
SET ROWCOUNT can sometimes be a lot slower than TOP... if it turns out to be too slow, you could always use dynamic SQL (observing, of course, all the warnings about dynamic SQL that may be exposed to the outside world, etc).
DECLARE @Rows VARCHAR(10)
SET @Rows = 100
DECLARE @sql VARCHAR(8000)
SET @sql = 'SELECT TOP ' + @Rows + ' Fname, Lname, Addr1, Addr2, City, State, Zip, phone FROM tblname'
EXEC (@SQL)
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply