|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 30, 2012 1:50 AM
Points: 143,
Visits: 79
|
|
Yeah thanks...
Now i got it...
Thanks for your reply..!!!
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, September 19, 2012 8:39 AM
Points: 595,
Visits: 1,226
|
|
Yep. @@rowcount is a cruel mistress. I avoid her like a rash.
Converting oxygen into carbon dioxide, since 1955.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Today @ 7:19 AM
Points: 18,733,
Visits: 12,331
|
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Tuesday, October 05, 2010 6:49 AM
Points: 611,
Visits: 29
|
|
Nice question, but, if we run the given script, don't we have an error on this line ?
select @@rowcount-- check this one out
EuG
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 30, 2012 1:50 AM
Points: 143,
Visits: 79
|
|
No.. i'm not getting any error..
are you??
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 10:54 AM
Points: 356,
Visits: 753
|
|
The only errors encounted would be if you didn't have the database and table already created as the script relies on them existing.
There's nothing wrong with SELECT @@ROWCOUNT -- a comment
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Tuesday, October 05, 2010 6:49 AM
Points: 611,
Visits: 29
|
|
Ok, but i thought there was a missing blank between "rowcount" and "--"...
EuG
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 10:54 AM
Points: 356,
Visits: 753
|
|
I may be getting confused with what you're saying..
But all of this works fine
select @@rowcount-- check this one out
select @@rowcount -- check this one out
select @@rowcount -- check this one out
select @@rowcount -- check this one out
These would not work
select @@rowcount- - check this one out
select rowcount -- check this one out
select @@rowcount - - check this one out
select @@rowcount -- check this one out
We've a policy at work to use /* */ for comments where possible in case peeps run comments over a line... but it's also a pain in the backside if you want to comment out a block with these already in.
What I've found a bit weird is, if you run SELECT @@ROWCOUNT by itself in a completely fresh window then you get 1 returned... slightly odd behaviour? For example run the below script, I've used different commenting in case of line wrapping.
SELECT @@ROWCOUNT /* Will return 1, even though we've not previousiy run a statement */
SELECT 1 WHERE 2 = 1 /* Will an empty record set */
SELECT @@ROWCOUNT /* Will return 0 as expected as the previous statement returned no rows */
SELECT @@ROWCOUNT /* Will return 1 as the previous statement returned a row i.e of 0 */
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 19, 2011 7:26 AM
Points: 1,078,
Visits: 289
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 12:39 PM
Points: 1,662,
Visits: 1,708
|
|
Fozzie (8/5/2010) What I've found a bit weird is, if you run SELECT @@ROWCOUNT by itself in a completely fresh window then you get 1 returned... slightly odd behaviour?
I think that there was a QotD about this in the past and it generated a lot of posts due to this behaviour. It is actually by design, and it all depends on what happens when you open first window. For example, if you open SSMS, open new window then @@rowcount is 1, but if you after opening new window go after database list dropdown and pick your database then select @@rowcount returns 0 simply because clicking in the dropdown silently issued use [your_db_name]; prior to you running select @@rowcount. Whatever settings are silently ran by SSMS depends on things such as your user options, database options, SSMS version etc. The bottom line is that when you open SSMS and do see select @@rowcount returns 1 out of the bat then it simply means that the latest silently executed for you by SSMS script affected one record.
Oleg
|
|
|
|