|
I posted a thread a while ago, which I currently
found the answer too..
Just thought I'd throw it out in the
world!
SET ROWCOUNT @intTop
CURSOR ETC.
HERE.....
SET ROWCOUNT 0
- From: Daniel Morphett
- To: CFAussie
Mailing List
- Sent: Tuesday, February 11, 2003 4:23 PM
- Subject: [cfaussie] Re: [OT] SP Cursor
- Don't think the select statement in a cursor can be dynamic.
- Couple of questions beg:
- if you're selecting top 1 from a table, there is no need for a
cursor
- if you know the number of rows you want to process (i.e. top 20),
you could easily just make a counter, incrementing it with each
row
- I notice you don't have an order by clause, which I reckon you are
going to need for a top n query.
- At 02:59 PM 2/11/2003 +1000, you wrote:
- I have the following cursor in my Stored Procedure
-
- -----------------------------------------------------
- DECLARE crsPoll CURSOR
- FOR SELECT TOP 1
- column1, column2
- FROM table
- -----------------------------------------------------
-
- I need the TOP 1 integer to be a variable, i.e. TOP @intTop
-
- But this won't work, it says "Incorrect Syntax"
-
- I also tried to set the whole select statement as variable and
then execute it like so;
-
- -----------------------------------------------------
- DECLARE crsPoll CURSOR
- FOR EXECUTE sp_executesql @sql
- -----------------------------------------------------
-
- Where the variable @sql is
-
- -----------------------------------------------------
- DECLARE @sql NVARCHAR(1024)
- SET @sql = 'SELECT TOP ' + CAST(@intTop AS VARCHAR(3)) + '
- column1, column2
- FROM table'
- -----------------------------------------------------
-
- But still no luck..
- Any ideas?
- ---
- You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
- To unsubscribe send a blank email to
[EMAIL PROTECTED]
- MX Downunder AsiaPac DevCon - http://mxdu.com/
- Daniel Morphett
- Web Developer, DBA
- www.daemon.com.au ---
- You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
- To unsubscribe send a blank email to
[EMAIL PROTECTED]
- MX Downunder AsiaPac DevCon - http://mxdu.com/
--- You are
currently subscribed to cfaussie as: [EMAIL PROTECTED] To
unsubscribe send a blank email to
[EMAIL PROTECTED]
MX Downunder AsiaPac
DevCon - http://mxdu.com/
Daniel Morphett Web Developer, DBA www.daemon.com.au
--- You are currently subscribed to cfaussie as:
[EMAIL PROTECTED] To unsubscribe send a blank email to
[EMAIL PROTECTED]
MX Downunder AsiaPac DevCon
- http://mxdu.com/ --- You are currently subscribed to
cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to
[EMAIL PROTECTED]
MX Downunder AsiaPac DevCon -
http://mxdu.com/
---
You are currently subscribed to cfaussie as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MX Downunder AsiaPac DevCon - http://mxdu.com/
|