﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Jason S Wong  / Transaction rowcount / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 19:08:14 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>nice tidy question with no tricks.  clear explanation.</description><pubDate>Sat, 16 Oct 2010 12:57:25 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>I agree Fozzie !</description><pubDate>Thu, 05 Aug 2010 10:15:45 GMT</pubDate><dc:creator>EugeneMoulin</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Oleg,Thanks for the heads up and clear explanation, does make a lot of sense. Will probably remember that one for a long time. :-)Eugene, Whilst it's not neccessary to have a space between the code and the comment, it's certainly nicer on the eye. The code highlighter on the forum makes it look wrong as it only identifies whole words. Generally I'd have the spaces, as though I could write this:[code]SELECT 1 FROM[dbo].[table][/code]It's not as well written, from my opinion as - plus you're less likely to get into trouble...[code]SELECT 1 FROM [dbo].[table][/code]</description><pubDate>Thu, 05 Aug 2010 09:57:57 GMT</pubDate><dc:creator>Fozzie</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Ok, i didn't run the script of the question, but i thought the blank between end of line and "--" was mandatory.Thanks anyway for your answer and explanation.EuG</description><pubDate>Thu, 05 Aug 2010 09:34:07 GMT</pubDate><dc:creator>EugeneMoulin</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>[quote][b]Fozzie (8/5/2010)[/b][hr]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?[/quote]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 [i][b]by design[/b][/i], and it all depends on what happens when you open first &amp;#119;indow. For example, if you open SSMS, open new window then [b]@@rowcount[/b] is [b]1[/b], but if you after opening new window go after database list dropdown and pick your database then [b]select @@rowcount[/b] returns [b]0[/b] simply because clicking in the dropdown silently issued[b] use [your_db_name];[/b] prior to you running [b]select @@rowcount[/b]. 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 [b]do[/b] see [b]select @@rowcount[/b] returns [b]1[/b] out of the bat then it simply means that the latest silently executed for you by SSMS script affected one record.Oleg</description><pubDate>Thu, 05 Aug 2010 09:29:07 GMT</pubDate><dc:creator>Oleg Netchaev</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Nice question.</description><pubDate>Thu, 05 Aug 2010 08:29:26 GMT</pubDate><dc:creator>Dennissinned</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>I may be getting confused with what you're saying..But all of this works fine[code]select @@rowcount-- check this one outselect @@rowcount -- check this one outselect @@rowcount  -- check this one outselect @@rowcount  -- check this one out[/code]These would not work[code]select @@rowcount- - check this one outselect rowcount -- check this one outselect @@rowcount -- check this one outselect @@rowcount -- checkthis one out[/code]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.[code]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 */[/code]</description><pubDate>Thu, 05 Aug 2010 04:07:11 GMT</pubDate><dc:creator>Fozzie</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Ok, but i thought there was a missing blank between "rowcount" and "--"...EuG</description><pubDate>Thu, 05 Aug 2010 03:51:39 GMT</pubDate><dc:creator>EugeneMoulin</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>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</description><pubDate>Thu, 05 Aug 2010 03:09:31 GMT</pubDate><dc:creator>Fozzie</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>No.. i'm not getting any error..are you??</description><pubDate>Thu, 05 Aug 2010 02:58:53 GMT</pubDate><dc:creator>sakthimadan</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Nice question, but, if we run the given script, don't we have an error on this line ?[code="sql"]select @@rowcount-- check this one out[/code]EuG</description><pubDate>Thu, 05 Aug 2010 02:19:22 GMT</pubDate><dc:creator>EugeneMoulin</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Nice question.  Thanks.</description><pubDate>Tue, 03 Aug 2010 15:01:28 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Yep.  @@rowcount is a cruel mistress.  I avoid her like a rash.  :-D</description><pubDate>Tue, 03 Aug 2010 10:30:44 GMT</pubDate><dc:creator>Steve Cullen</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Yeah thanks...Now i got it...Thanks for your reply..!!!</description><pubDate>Tue, 03 Aug 2010 02:20:07 GMT</pubDate><dc:creator>sakthimadan</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>sakthi_madan,Run in query analyser:SELECT @@ROWCOUNTSELECT @@ROWCOUNTThe first statement returns a row with 0 The second statement is the count of rows returned from the first, i.e 1 row of 0.Hope that makes sense.I got the answer wrong as well... so close yet so far. Good question.Kev</description><pubDate>Tue, 03 Aug 2010 02:09:34 GMT</pubDate><dc:creator>Fozzie</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Can anyone explain me, how does it return '1' as the last rowcount???</description><pubDate>Mon, 02 Aug 2010 21:29:12 GMT</pubDate><dc:creator>sakthimadan</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Nice question.  You got me with the last SELECT setting the value to 1.  I thought it returned 0.</description><pubDate>Mon, 02 Aug 2010 13:58:17 GMT</pubDate><dc:creator>Robert Frasca</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>good question</description><pubDate>Mon, 02 Aug 2010 00:08:20 GMT</pubDate><dc:creator>pankaj upadhyay</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>nice!! but tough to concentrate........</description><pubDate>Sun, 01 Aug 2010 23:55:10 GMT</pubDate><dc:creator>udayroy15</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>a very good question... thanks :-)</description><pubDate>Sun, 01 Aug 2010 23:13:32 GMT</pubDate><dc:creator>ziangij</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Nice question, thanks!</description><pubDate>Sun, 01 Aug 2010 23:04:26 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Nice question, I liked that it is clean and straightforward, no tricks. The column names in that table of yours are not very nice though. :-DOleg</description><pubDate>Sun, 01 Aug 2010 20:57:12 GMT</pubDate><dc:creator>Oleg Netchaev</dc:creator></item><item><title>RE: Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Nice question</description><pubDate>Sat, 31 Jul 2010 15:15:53 GMT</pubDate><dc:creator>bitbucket-25253</dc:creator></item><item><title>Transaction rowcount</title><link>http://www.sqlservercentral.com/Forums/Topic961794-1665-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/Transaction/69322/"&gt;Transaction rowcount&lt;/A&gt;[/B]</description><pubDate>Sat, 31 Jul 2010 13:22:42 GMT</pubDate><dc:creator>Repriser-991084</dc:creator></item></channel></rss>