July 23, 2012 at 11:14 am
Excellent QotD -- thanks!
July 23, 2012 at 11:20 am
The first SET DATEFORMAT is what started to throw me, then I realized that it wouldn't lay a part in the conversion of the date literals when the view was queried.
Very similar to a question back on June 6, 2012. Easier to read the answers though.
Definately needed considering the number of wrong answers at this time (65% Wrong).
July 24, 2012 at 4:44 pm
When i run this question on SQL Server 2008 gave me (0,0).
July 24, 2012 at 6:03 pm
ehab.abuzied (7/24/2012)
When i run this question on SQL Server 2008 gave me (0,0).
You may want to double check the codee you ran. I ran it on SQL Server2008 R2 and it returns the correct answer.
July 25, 2012 at 7:55 pm
SQLRNNR (7/23/2012)
Seems very similar to another we had recently.
Yes, it's very like a recent one.
Judging by the numbers getting it wrong it still needs airing. So a good question.
Tom
July 29, 2012 at 3:32 am
It is simply not a correct question and answer. the answer MIGHT be what the author of the question says, but it can also be 1,1. It depends on the regional setting as the author writes.
I have now tested on my sql server, and I got 1,1 with this code
set dateformat Ymd
go
select COUNT(*) as firstcount
from testdates where dt1=dt2
set dateformat Ydm
select COUNT(*) as secondcount
from testdates where dt1=dt2
So this is, as I see it, a question with multiple answers.
July 29, 2012 at 3:21 pm
sj 74463 (7/29/2012)
It is simply not a correct question and answer. the answer MIGHT be what the author of the question says, but it can also be 1,1. It depends on the regional setting as the author writes.I have now tested on my sql server, and I got 1,1 with this code
set dateformat Ymd
go
select COUNT(*) as firstcount
from testdates where dt1=dt2
set dateformat Ydm
select COUNT(*) as secondcount
from testdates where dt1=dt2
So this is, as I see it, a question with multiple answers.
Can you post your definition of testdates? Also what results do you get with the script below
IF OBJECT_ID('DtView') IS NOT NULL DROP VIEW DtView;
GO
SET DATEFORMAT YDM
GO
CREATE VIEW DtView(dt1,dt2)
AS
SELECT CAST('2012-04-10' AS DATETIME),CAST('2012-04-10' AS DATE);
GO
SET DATEFORMAT YMD
GO
SELECT COUNT(*) AS FirstCount FROM DtView WHERE dt1=dt2;
GO
SET DATEFORMAT YDM
GO
SELECT COUNT(*) AS SecondCount FROM DtView WHERE dt1=dt2;
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537August 8, 2012 at 11:45 am
Good question, learned something today 😀
October 5, 2012 at 6:17 am
when i run that query I got answer as 1,1 and in poll its showing 1,0 as correct answer.
I dont know why...
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 9 posts - 16 through 23 (of 23 total)
You must be logged in to reply to this topic. Login to reply