April 11, 2008 at 8:54 am
Hi i'd like to give the user the option to enter in the top X to return the number of rows.
X = a number.
The default will be 100.
Is this possible to do in RS and if so can i get some pointers thanks
April 14, 2008 at 4:34 pm
if you're using a query (rather than a stored proc), you only need to create a report parameter and reference that parameter in a TOP clause:
select top(@parm) ... from ...
April 22, 2008 at 4:57 am
Hey i tested this and am getting a Error on the @Top paramter it seem to not like the @Top in the Select statement
April 22, 2008 at 6:33 am
top with a variable/parameter is valid SQL:
declare @top int
set @top = 25
select top(@top) * from [some_table]
can you post your query?
April 22, 2008 at 7:20 am
I copied your query into my QA and changed the table name and ran the query. It gave me a error
Here is the query
declare @top int
set @top = 25
select top (@top) * from barcode
Here is the Error
Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near '('.
I know this may seem silly to ask but would the way my SQL server is installed affect not being able to use a top variable. I i was getting this error in my report
'TOP clause Expressions' support not available in this server version.
April 22, 2008 at 7:24 am
Are you using SQL Server 2000 or 2005? I think 2000 doesn't support TOP with a variable.
John
April 22, 2008 at 7:26 am
Am using 2000 but its on 2005 interface. So is there away around this ?
April 22, 2008 at 7:36 am
You have two options. You can build your SQL string with @top as a parameter and execute it using sp_executesql, or you can use SET ROWCOUNT, which does allow a variable.
John
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply