June 11, 2012 at 8:39 pm
Comments posted to this topic are about the item INTERSECT 1
June 11, 2012 at 11:15 pm
Nice question.
Link to the INTERSECT page:
http://msdn.microsoft.com/en-us/library/ms188055(SQL.105).aspx
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
June 12, 2012 at 1:48 am
Thanks for the question, Ron. And thanks Koen for the extra link.
In case someone is wondering why the different data types have no effect - Ron included the relevant link, but didn't explicitly describe this in his explanation, so I will. The data types are compared to find the one with the highest precedence. It's char(2) vs bigint, so if you check Ron's link, you'll see that bigint wins. SQL Server then checks to see if implicit conversion is allowed for char to biging; this is the case, so the query compiles and a plan is created. During execution time, all char(2) values are converted to bigint, and then the INTERSECT operation is carried out.
If you change one of the values in the char(2) column to be something that doesn't convert to biging (e.g. 'a'), you'll get a run-time error.
June 12, 2012 at 1:59 am
This was removed by the editor as SPAM
June 12, 2012 at 2:33 am
Hugo Kornelis (6/12/2012)
Thanks for the question, Ron. And thanks Koen for the extra link.In case someone is wondering why the different data types have no effect - Ron included the relevant link, but didn't explicitly describe this in his explanation, so I will. The data types are compared to find the one with the highest precedence. It's char(2) vs bigint, so if you check Ron's link, you'll see that bigint wins. SQL Server then checks to see if implicit conversion is allowed for char to biging; this is the case, so the query compiles and a plan is created. During execution time, all char(2) values are converted to bigint, and then the INTERSECT operation is carried out.
If you change one of the values in the char(2) column to be something that doesn't convert to biging (e.g. 'a'), you'll get a run-time error.
Thanks for the additional explanation which you have explaned in a clear simple manner something one does not often find in BOL ... I am sure it will be appreciated by all those who read your posting.
June 12, 2012 at 6:50 am
Thanks for the question!
June 12, 2012 at 7:56 am
Good one.
M&M
June 12, 2012 at 8:33 am
Thanks for the question - cheers
June 12, 2012 at 8:55 am
Interesting! Thanks for the question, and thanks for the additional explaination of the type conversion Hugo!
June 12, 2012 at 9:05 am
A really good one - thanks, Ron!
June 12, 2012 at 9:10 am
June 12, 2012 at 11:43 am
Great question and dialogue. Thanks!
June 13, 2012 at 8:42 am
Nice tidy question, that brings up two importan fundamentals:
(1) intersection returns distinct values not duplicates
(2) equality tests do implicit conversion where needed, from lower precedence type to higher.
Tom
June 18, 2012 at 11:35 am
Hugo,
Thanks for the further explanation that supports the correct answer.
June 18, 2012 at 11:36 am
Nice question on the topic.
Thanks.
Viewing 15 posts - 1 through 15 (of 22 total)
You must be logged in to reply to this topic. Login to reply