Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


BETWEEN


BETWEEN

Author
Message
VALEK
VALEK
Old Hand
Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)

Group: General Forum Members
Points: 388 Visits: 462
OKAY similar test.

Q: Will the statement
SELECT 12345 AS AGE
return the same result as
SELECT TOP 1 Age FROM CUSTOMERS
?

M.Sc.IT, M.B.A, MCTS BI 2008, MCITP BI 2008, MCTS SQL Dev, CSM, CDVDM
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24157 Visits: 37927
Not even similiar. Let me know when you decide to give up trying to convince me otherwise.

Cool

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
VALEK
VALEK
Old Hand
Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)

Group: General Forum Members
Points: 388 Visits: 462
Lynn Pettis (6/10/2008)
Not even similiar. Let me know when you decide to give up trying to convince me otherwise.
Cool

Quite similar.
One query returns a constant and the other returns a random figure.
Q: Is the result same after the execution? A: unknown (even though there should not be anyone in CUSTOMERS aged 12345 years, but there is a slim possibility that the first AGE will be 12345)

sp: remember the million monkeys vs typing machines trying to get Romeo&Juliet typed?

M.Sc.IT, M.B.A, MCTS BI 2008, MCITP BI 2008, MCTS SQL Dev, CSM, CDVDM
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24157 Visits: 37927
One query is returning a constant, the other a value from a table.

Where is the simularity between the queries?

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

Cool

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
VALEK
VALEK
Old Hand
Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)

Group: General Forum Members
Points: 388 Visits: 462

Where is the simularity between the queries?
Both return a single value (or an empty set).

[quote]
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.

M.Sc.IT, M.B.A, MCTS BI 2008, MCITP BI 2008, MCTS SQL Dev, CSM, CDVDM
majorbloodnock
majorbloodnock
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1113 Visits: 3062
VALEK (6/10/2008)

Where is the simularity between the queries?
Both return a single value (or an empty set).

[quote]
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, sumus solum profundum variat
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44871 Visits: 39851
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! Wink

--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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is usually not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24157 Visits: 37927
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.

Cool

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
VALEK
VALEK
Old Hand
Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)

Group: General Forum Members
Points: 388 Visits: 462


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
VALEK
VALEK
Old Hand
Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)

Group: General Forum Members
Points: 388 Visits: 462
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.
Cool


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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search