|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 5:02 AM
Points: 1,149,
Visits: 1,451
|
|
Igor, congratulations on finding an easy way to pad your score! 
Steve, Thanks for the question.
Please don't go. The drones need you. They look up to you.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:49 AM
Points: 5,235,
Visits: 7,035
|
|
Nice question on a little known (and, frankly, barely useful) feature. Too bad it is hampered by the all too common mistake of depending on a time format. In some regions of the world, the test table has data for January 1st, February 1st, March 1st, and May 1st. #FeelingLikeBrokenRecord
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Yesterday @ 6:03 AM
Points: 720,
Visits: 1,197
|
|
Hugo Kornelis (3/21/2012) Nice question on a little known (and, frankly, barely useful) feature. Too bad it is hampered by the all too common mistake of depending on a time format. In some regions of the world, the test table has data for January 1st, February 1st, March 1st, and May 1st. #FeelingLikeBrokenRecord
Hugo, According to my reading... this question doesn't care which date format (other than the answer that specifies Jan 3rd) it is using. In most, if not all, regions I would suppose that it would return all dates.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:49 AM
Points: 5,235,
Visits: 7,035
|
|
venoym (3/21/2012)
Hugo Kornelis (3/21/2012) Nice question on a little known (and, frankly, barely useful) feature. Too bad it is hampered by the all too common mistake of depending on a time format. In some regions of the world, the test table has data for January 1st, February 1st, March 1st, and May 1st. #FeelingLikeBrokenRecordHugo, According to my reading... this question doesn't care which date format (other than the answer that specifies Jan 3rd) it is using. In most, if not all, regions I would suppose that it would return all dates. True; for those who blindly copy and paste the code, it will not make a difference. To those who try to work out the answer in their head, it may make a difference if they see the "Jan 3" in the text of the question.
Until I discovered the "incorrect" use of ANY and realised that this is what the question is about, I suspected that the question might be a trick question on date formats.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:20 PM
Points: 2,573,
Visits: 1,531
|
|
| I had only looked at the ANY and SOME syntax once before and did not see a need for them. They seem to perform exactly like the IN statement unless I am missing something. Are there any instances where you could not perform the same logic using IN instead of ANY?
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
KWymore (3/21/2012) I had only looked at the ANY and SOME syntax once before and did not see a need for them. They seem to perform exactly like the IN statement unless I am missing something. Are there any instances where you could not perform the same logic using IN instead of ANY?
You can use inequality comparisons with Any/Some. For example:
SELECT * FROM ( VALUES ( 1), ( 2), ( 3) ) AS MyQuery (MyCol) WHERE MyCol > ANY ( SELECT MyCol2 FROM ( VALUES ( 2), ( 3) ) AS MyQuery2 (MyCol2) ) ; Note the use of ">ANY". IN will only do equality comparisons.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:49 AM
Points: 5,235,
Visits: 7,035
|
|
KWymore (3/21/2012) Are there any instances where you could not perform the same logic using IN instead of ANY? Yes, as GSquared already shows. However, there are (as far as I know) no cases where an ANY or SOME could not be replaced by an equivalent EXISTS subquery.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 5:11 AM
Points: 1,371,
Visits: 454
|
|
Nice question.
----------------- Gobikannan
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
Hugo Kornelis (3/21/2012)
KWymore (3/21/2012) Are there any instances where you could not perform the same logic using IN instead of ANY?Yes, as GSquared already shows. However, there are (as far as I know) no cases where an ANY or SOME could not be replaced by an equivalent EXISTS subquery.
There are always alternatives to any particular query syntax. These options (Any/Some/All) can make a query significantly more readable than some complex Exists subqueries, in the right cases.
I haven't tested them for performance, nor have I used them with any frequency, so can't speak to that point, but a QotD that highlights a less-known feature for possible use, is perfectly valid.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:20 PM
Points: 2,573,
Visits: 1,531
|
|
GSquared (3/21/2012)
Hugo Kornelis (3/21/2012)
KWymore (3/21/2012) Are there any instances where you could not perform the same logic using IN instead of ANY?Yes, as GSquared already shows. However, there are (as far as I know) no cases where an ANY or SOME could not be replaced by an equivalent EXISTS subquery. There are always alternatives to any particular query syntax. These options (Any/Some/All) can make a query significantly more readable than some complex Exists subqueries, in the right cases. I haven't tested them for performance, nor have I used them with any frequency, so can't speak to that point, but a QotD that highlights a less-known feature for possible use, is perfectly valid.
I would end up using Exists/Not Exists for these scenarios. However, I do see your point on readability as I have written some fairly complex, ugly Exists statements before. I will have to keep ANY/ALL in mind then for these scenarios.
|
|
|
|