dbTalk Databases Forums  

Getting the SET ROWCOUNT Value

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Getting the SET ROWCOUNT Value in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gene Wirchenko
 
Posts: n/a

Default Getting the SET ROWCOUNT Value - 12-23-2010 , 08:35 PM






Hello:

Is there any way to get the SET ROWCOUNT value?

No, I do not mean @@ROWCOUNT. Due to this name collision, I have
not found an answer in my searching. What would replace the blanks in
the code below if I want to see the results 10 then 0?

set rowcount 10
_____
set rowcount 0
_____

Generalise to any SET parameter values.

Pointers welcome.

Sincerely,

Gene Wirchenko

Reply With Quote
  #2  
Old   
Jeroen Mostert
 
Posts: n/a

Default Re: Getting the SET ROWCOUNT Value - 12-24-2010 , 12:16 AM






On 2010-12-24 03:35, Gene Wirchenko wrote:
Quote:
Is there any way to get the SET ROWCOUNT value?

Here's one I can think of, though it's probably not what you where hinting at:

DECLARE @c INT;
SET ROWCOUNT 10;
SELECT @c = n FROM Nums ORDER BY n;
SET ROWCOUNT 0;
SELECT @c + 1;

I assume you've got a "nums" table, of course (mine contains zero, hence the
+1).

Quote:
Generalise to any SET parameter values.

If you mean any possible *kind* of SET parameter (so not just SET ROWCOUNT),
then take a peek:

SELECT * FROM sys.dm_exec_sessions WHERE session_id = @@SPID;

Beware, the table has a row_count column but this does *not* correspond to
the ROWCOUNT setting (I'm not exactly sure what it *is* supposed to contain,
despite BOL describing it as "Number of rows returned on the session up to
this point").

--
J.

Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Getting the SET ROWCOUNT Value - 12-24-2010 , 04:44 AM



Gene Wirchenko (genew (AT) ocis (DOT) net) writes:
Quote:
Is there any way to get the SET ROWCOUNT value?
I can't really think of a good way. You could to "SELECT 1 INTO #temp FROM
bigtable" and then check @@rowcount, but it's not good for performance when
SET ROWCOUNT is 0.

In any case, I recommend against any use of SET ROWCOUNT. This is a very
old command, which predates TOP and cursors. I see little reason to use it
today, and if it was up to me, it would be taken out of the product.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.