Rowcount

  • The requirements for this questions don't seem to support the given answer. Upon reading the question, my initial reaction was that the results would be 0,1.

    Upon opening a new query window and executing the code, I received the results 1,1. If the code was dependent on having set NOCOUNT ON, then that should have been specified in the requirements.

    This is one of the most common problems I have seen in development efforts. Poor, or lacking, requirements will result in unexpected results.

  • I also tested the code and got 1,1.

    So I would have had the wrong answer even testing the code?

    What is that Question good for if there are multiple result?

  • Another QOTD where either the answer is "It depends" and/or inadequate information is given. I knew that the answer was (x,1) but there's not enough information to determine x. If my previous query had been "select * from sys.databases" then x will probably be a number larger than one. If it had been "select * from sys.databases where 0 = 1" then x is zero. If a new query window is opened then it depends on the tool (SSMS, Query Analyzer...).

  • fallenstudent (1/29/2010)


    I also tested the code and got 1,1.

    So I would have had the wrong answer even testing the code?

    Nobody can tell if you would have had the right or wrong answer because it depends on what you use when "testing the code."

  • hate to beat a dead horse. but anytime i execute this in a query window it returns 1,1 ... i also thought it would be 0,1 but was intrigued by it so thus i tested it.

  • I ran it in a clean window with no previous queries run in SQL 7 & 2005 and they both returned 1,1. Also, the question did not state to run it with nocount on....I rarely turn that option on in a query window because I WANT to see how many are returned.

    D

  • I agree with user "malleswarareddy_m", this question is improper

  • I'm using sql 2008, and as others have stated, if I do SET NOCOUNT ON and then run the queries, I get 0,1. Without it, I get 1,1.

    Amu

  • Same here.

  • amarshall-568002 (1/29/2010)


    I'm using sql 2008, and as others have stated, if I do SET NOCOUNT ON and then run the queries, I get 0,1. Without it, I get 1,1.

    Amu

    Yes but that's not what the code in the question says :w00t:.

  • While intuitively I expected a result set of (0,1), I must echo what everyone else has said, I also achieved the results set of (1,1) when I tested it for myself.

  • This might be a interesting question , but i don't think so..coz u should mention the server wheather it is 2k/05/08.As u gave ans 0 ,1 it is correct in 2k but not in 2005. could u please elaborate.so that i'll satisfy...?

    Thanks
    SUrya

  • Since the question asks what the output of

    SELECT @@ROWCOUNT

    SELECT @@ROWCOUNT

    then the answer must be 1,1 or perhaps an answer that was not offered "It depends". No one can reasonably assume that SQL 2000 was being used or that using SET NOCOUNT ON is required to meet the authors objective.

    Scott

  • I experienced 1,1 also. The ms link provided concerning rowcount had this to say:"Statements that make a simple assignment always set the @@ROWCOUNT value to 1. No rows are sent to the client. Examples of these statements are: SET @local_variable, RETURN, READTEXT, and select without query statements such as SELECT GETDATE() or SELECT 'Generic Text'."

  • The answer is absolutely 1,1 because of the way the question was asked. It does not mention anything about a pre-used query window. When you open a new query window, an immediate @@ROWCOUNT will always return a 1. This is an incorrect return, but it is what it is.

Viewing 15 posts - 61 through 75 (of 132 total)

You must be logged in to reply to this topic. Login to reply