• That was fun and surprising. I didn't notice the quirky update until I ran it.

    Thanks for a good QotD.

    Rune Bivrin (4/14/2010)


    It's important to note that SET @result = cast (@@rowcount as varchar) does NOT change @@ROWCOUNT. The first 1 comes from the last INSERT #n VALUES(3).

    This is one of the important differences between SELECT and SET when assigning variables. SET never yields a rowcount, and thus doesn't change @@ROWCOUNT.

    That does not seem to be true. @@ROWCOUNT yields the result of the last command. SET yields 1 whereas PRINT yields 0.

    declare @n varchar(5)

    select @n = @@rowcount

    /*Row count is 1 after SELECT*/

    print @@rowcount

    /*Row count is 0 after PRINT*/

    print @@rowcount

    set @n = @@rowcount

    /*Row count is 1 after SET*/

    print @@rowcount

    Tom Garth
    Vertical Solutions[/url]

    "There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers