BETWEEN

  • VALEK (6/10/2008)


    Where is the simularity between the queries?

    Both return a single value (or an empty set).

    Give it up. Neither of us is going to change the others minds on this.

    Not really. We WILL change it and we already HAVE! I am sure that the ones reading the thread see how it is possible to confuse an obvious.

    ps: I answered the original question correctly FYI, but I just wasnot happy with the way the question was asked and the tools used to generate a testbed. QA engineers and Professional Software Testers will know what I am talking about.

    Umm.... Were you suggesting that QA engineers and Professional Software Testers didn't know about this before you mentioned it?

    In a medium such as a forum, it's all too easy for what you say to actually be different from what you mean. I don't think it was your intention, but it comes across as a little arrogant to imply that, just because your posts are on public display, your comments within have illuminated something previously not understood and, as a result have changed people's minds. Personally, I understood right from the start what people's issues are with the question, I understand very well just how easy it is to obfuscate the obvious, and I still disagree with the point you're trying to make.

    Semper in excretia, suus solum profundum variat

  • VALEK (6/10/2008)


    ps: I answered the original question correctly FYI, but I just wasnot happy with ... the tools used to generate a testbed. QA engineers and Professional Software Testers will know what I am talking about.

    As one who helps "QA Engineers and Professional Software Testers" figure out their tests setups, I have to say that comes across as being pretty arrogant... Unnecessary, too! 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • To paraphrase what someone else once said on this site, "The proof is in the code." Here is the code:

    set nocount on;

    create table #fun(id int identity(1,1) primary key clustered, crit int);

    create table #testresults(RunId int identity(1,1),Statement1Count int,Statement2Count int, SameResults int);

    declare @LoopCnt int,

    @Statement1Count int,

    @Statement2Count int,

    @SameResults int

    set @LoopCnt = 0;

    while @LoopCnt < 100

    begin

    insert #fun(crit)

    select top 250000

    rand(checksum(newid()))* 10

    from

    master.sys.columns sc1

    cross join master.sys.columns sc2;

    --select statement #1

    select

    @Statement1Count = count(*)

    from

    #fun

    where

    crit between 3 and 5;

    --select statement #2

    select

    @Statement2Count = count(*)

    from

    #fun

    where

    crit between 5 and 3;

    if @Statement1Count = @Statement2Count

    set @SameResults = 1

    else

    set @SameResults = 0;

    insert #testresults(Statement1Count,Statement2Count, SameResults)

    values (@Statement1Count,@Statement2Count,@SameResults);

    set @LoopCnt = @LoopCnt + 1;

    truncate table #fun;

    end

    select count(SameResults) from #testresults where SameResults = 1;

    select count(*) from #testresults;

    select * from #testresults;

    --Would statements #1 and #2 consistently return the same result set?

    drop table #fun

    drop table #testresults

    set nocount off;

    Here are the results:

    RunId Statement1Count Statement2Count SameResults

    1 75342 0 0

    2 74807 0 0

    3 75012 0 0

    4 75279 0 0

    5 75209 0 0

    6 75318 0 0

    7 74784 0 0

    8 75126 0 0

    9 74941 0 0

    10 74954 0 0

    11 75343 0 0

    12 75624 0 0

    13 75054 0 0

    14 75048 0 0

    15 75025 0 0

    16 75224 0 0

    17 75344 0 0

    18 75168 0 0

    19 74804 0 0

    20 75121 0 0

    21 74586 0 0

    22 75032 0 0

    23 74255 0 0

    24 74767 0 0

    25 74911 0 0

    26 75152 0 0

    27 74967 0 0

    28 74858 0 0

    29 75504 0 0

    30 74795 0 0

    31 75155 0 0

    32 75341 0 0

    33 75017 0 0

    34 74819 0 0

    35 74857 0 0

    36 75227 0 0

    37 74494 0 0

    38 74601 0 0

    39 75014 0 0

    40 74990 0 0

    41 74840 0 0

    42 74919 0 0

    43 75454 0 0

    44 75277 0 0

    45 74750 0 0

    46 75060 0 0

    47 74799 0 0

    48 75164 0 0

    49 75203 0 0

    50 74809 0 0

    51 75023 0 0

    52 75022 0 0

    53 74695 0 0

    54 74806 0 0

    55 75105 0 0

    56 74994 0 0

    57 75680 0 0

    58 75177 0 0

    59 74771 0 0

    60 75105 0 0

    61 75144 0 0

    62 74399 0 0

    63 74687 0 0

    64 74822 0 0

    65 75025 0 0

    66 75120 0 0

    67 74933 0 0

    68 75118 0 0

    69 74860 0 0

    70 75150 0 0

    71 74826 0 0

    72 74896 0 0

    73 75303 0 0

    74 75305 0 0

    75 75334 0 0

    76 74875 0 0

    77 74756 0 0

    78 75054 0 0

    79 75041 0 0

    80 74729 0 0

    81 75295 0 0

    82 74847 0 0

    83 75064 0 0

    84 75059 0 0

    85 75302 0 0

    86 75237 0 0

    87 74964 0 0

    88 75161 0 0

    89 75107 0 0

    90 74693 0 0

    91 74608 0 0

    92 75035 0 0

    93 75360 0 0

    94 74867 0 0

    95 74739 0 0

    96 75181 0 0

    97 74855 0 0

    98 75263 0 0

    99 74726 0 0

    100 75026 0 0

    Based on the results, the answer is still NO.

    😎

  • Umm.... Were you suggesting that QA engineers and Professional Software Testers didn't know about this before you mentioned it?

    I suggest right the opposite.

    Coming back to the question and the answers. I have participated in dozens of programming contests, including international ones and team programming contests, and have seen hundreds of assignments, tasks, and multiple choice questions related to programming, maths, algebra, physics, computing etc.

    Sorry to say, but the questions in the subject sucks!!!

    The reason being is that the precise function which is BETWEEN is used over random data.

    Precise answers such as YES and NO by definition are not right (with rare exceptions), NOT DEFINED is the only correct answer in this case.

    If the question creator did not want to have this discussion, he should not have used random figures, as I mentioned. He should have used a gradient or other predictable function such as SIN, COS, MOD etc.

    ps: I am sure there would be many people thinking like me, they just either don't read this forum or save their (and their company) time.

    M.Sc.IT, M.B.A, MCTS BI 2008, MCITP BI 2008, MCTS SQL Dev, CSM, CDVDM

  • Lynn Pettis (6/11/2008)


    To paraphrase what someone else once said on this site, "The proof is in the code." Here is the code:

    ...

    while @LoopCnt < 100

    ...

    Based on the results, the answer is still NO.

    😎

    Replace the code above wi th the following and comeback to me us the result (if you are still alive)

    ...

    while @LoopCnt < 1000000000000000000000000000000000000000000000

    ...

    Don't forget to write another script to analyse the result, since the output will be quite long.

    M.Sc.IT, M.B.A, MCTS BI 2008, MCITP BI 2008, MCTS SQL Dev, CSM, CDVDM

  • VALEK (6/11/2008)


    Lynn Pettis (6/11/2008)


    To paraphrase what someone else once said on this site, "The proof is in the code." Here is the code:

    ...

    while @LoopCnt < 100

    ...

    Based on the results, the answer is still NO.

    😎

    Replace the code above wi th the following and comeback to me us the result (if you are still alive)

    ...

    while @LoopCnt < 1000000000000000000000000000000000000000000000

    ...

    Don't forget to write another script to analyse the result, since the output will be quite long.

    It is in your court now. Sorry, but even if the two queries come back once with the same results, the answer is still NO. The reason is consistently return the same results. If BETWEEN 3 AND 5 was the same as BETWEEN 5 AND 3, the results of each run would have been consistant between the two queries.

    😎

  • It is in your court now. Sorry, but even if the two queries come back once with the same results, the answer is still NO. The reason is consistently return the same results. If BETWEEN 3 AND 5 was the same as BETWEEN 5 AND 3, the results of each run would have been consistant between the two queries.

    😎

    Don't forget the third option: NOT KNOWN.

    We all know that the question was about BETWEEN, so why the hell did they use RAND() and some dodgy table?

    I would phrase the question like this: do BETWEEN a AND b and BETWEEN b AND a in the WHERE clause have the same effect? YES/NO/UNKNOWN.

    Let's put a fullstop on this. Everyone knows now the mechanics of BETWEEN and difference between BETWEEN a AND b and BETWEEN b AND a. The problem is that for me as a mathematician and a programmer, the original question contained redundant and confusing irrelevant information. Nevertheless I answered the question correctly since I guessed the purpose and ignored the dodgyness of the testbed. Though I decided to raise the conversation for the conversation sake so that everyone knows that not all questions comes clear to everyone as it does to the person asking the question. Thats all.

    over

    M.Sc.IT, M.B.A, MCTS BI 2008, MCITP BI 2008, MCTS SQL Dev, CSM, CDVDM

  • ... and that's why I hate multiple-guess questions... gimme a good solid essay question or lemme write some code, instead!

    That was a fun conversation to watch... thanks, Gents. 🙂

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • VALEK (6/11/2008)


    Let's put a fullstop on this.

    Several people tried to do that a couple of pages ago, but you still wanted the last word. It was on page 4 of this thread that Lynn first said "I think we're going to have to agree to disagree".

    Everyone knows now the mechanics of BETWEEN and difference between BETWEEN a AND b and BETWEEN b AND a. The problem is that for me as a mathematician and a programmer, the original question contained redundant and confusing irrelevant information. Nevertheless I answered the question correctly since I guessed the purpose and ignored the dodgyness of the testbed. Though I decided to raise the conversation for the conversation sake so that everyone knows that not all questions comes clear to everyone as it does to the person asking the question. Thats all.

    over

    Is this still part of the "fullstop", or shall we call it a postscript? An appendix, perhaps?

    Semper in excretia, suus solum profundum variat

  • Wow!~ my own mini religious war! I have to say I'm impressed with how riled up we've managed to get....

    Anyway - like Steve has mentioned before - it might not be so easy as you think, so perhaps help bring up the quality of the questions by posting some of your own. Trying to ask something with a reasonable setup without necessarily shouting out the correct answer takes a bit of tuning, and I seem to have been a bit off-key on this one.

    I do think there's no doubt it could have been worded more clearly, so I can take these comments to mind for any other questions I might put out there.

    Anyway thanks! and I look forward to your collective contributions!

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Matt, I think to characterize this as a religious war is a little dramatic. I'd simply call it a strong difference of opinion.

    As I said earlier, I'll agree to disagree. It was a good question, and I would not classify it as a trick question. It tested you ones knowledge of the BETWEEN clause as implemented in T-SQL.

    😎

  • Oh fair enough Lynn. I just haven't been getting notified about posts, so coming back to find having ballooned out to 60 or so posts was astounding. But you're right - we're not talking NULLs handling or Identity fields, this is much milder....

    Still amazing how "lively" the debate gets to be:)

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Hmm.. Definitely open to interpretation.

    "Would statements #1 and #2 consistently return the same result set?"

    Yes, they would... Every time I run it, they consistently give me the same result set. The second one would just contain a zero.

    Needs re-writing or removal, methinks.

  • I'm with you on this one! The wording on the question was ambiguous and I interpreted it in a way that the writer did not intend...

  • Lynn Pettis (6/13/2008)


    I'd simply call it a strong difference of opinion.

    Heh... isn't that the way religious wars get started. 😛

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 15 posts - 46 through 60 (of 62 total)

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