|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 12:39 PM
Points: 5,103,
Visits: 20,220
|
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 2:11 AM
Points: 9,378,
Visits: 6,473
|
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 6:30 AM
Points: 3,192,
Visits: 4,151
|
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: 2 days ago @ 8:31 AM
Points: 3,129,
Visits: 4,312
|
|
Interesting question, thanks
____________________________________________ Space, the final frontier? not any more... All limits henceforth are self-imposed. “libera tute vulgaris ex”
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:49 PM
Points: 5,244,
Visits: 7,063
|
|
Nice question, Ron!
I only got it right because I figured that the relative order of the date and time related values would be "logical". And since the conversion to smalldatetime would chop off the seconds and the conversion to date the entire time portion, the only logical ordering of those three would be date / smalldatetim / datetime. So I knew that I was looking for an answer where the number 2 was before 3, and 3 before 5 - with the other two numbers at any possible location. My luck was that there was only one solution left after applying this filter! ;)
PS: Is the "weird" order of the colB values accidental, or a deliberate ploy to make the question even harder?
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Saturday, March 16, 2013 9:53 AM
Points: 847,
Visits: 768
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 10:51 AM
Points: 1,219,
Visits: 13,507
|
|
nice question!!!
thanks Ron!!!
rfr.ferrari DBA - SQL Server 2008 MCITP | MCTS
remember is live or suffer twice!
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: 2 days ago @ 8:52 AM
Points: 1,788,
Visits: 3,327
|
|
Good question, but I'm not sure that the explanation is 100% correct.
Because values from different data type families must be explicitly cast before being referenced in comparison predicates, the effects of the The values in the following table are examples of the rules regarding data type precedence.
The values in the sql_variant column are not casted/converted into a common data type prior to the ORDER BY. If there is data from different data type families, then the values are sorted based on the data type family precedence.
A quick example is if you add three values from the "Exact numeric" family and one from "Unicode" family.
create table #test(id int, val sql_variant)
insert into #test values(1,'2') insert into #test values(2,1) insert into #test values(3,3) insert into #test values(4,0)
select *,sql_variant_property(val,'BaseType') from #test order by val
/* Result */ id val (No column name) 1 2 varchar 4 0 int 2 1 int 3 3 int
As you can see when running this query, there is no casting of values between int and the varchar values in this column. The varchar (Unicode family) has lower precedence than int (Exact numeric family) and will always be lowest value.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 4:58 AM
Points: 1,152,
Visits: 1,457
|
|
Hugo Kornelis (11/10/2011) Nice question, Ron!
I only got it right because I figured that the relative order of the date and time related values would be "logical". And since the conversion to smalldatetime would chop off the seconds and the conversion to date the entire time portion, the only logical ordering of those three would be date / smalldatetim / datetime.
I used the same process, but was idiot enough to stop when I figured out the hierarchy of the data types (including the inferred position of date). Would have been beneficial to actual DO the process of type conversion! Well, at least NOW my mind is working this morning! 
Thanks for the question.
Please don't go. The drones need you. They look up to you.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 6:30 AM
Points: 3,192,
Visits: 4,151
|
|
Nils Gustav Stråbø (11/10/2011) Good question, but I'm not sure that the explanation is 100% correct.
I'm sure that the part of the explanation was deleted by accident:
Because values from different data type families must be explicitly cast before being referenced in comparison predicates, the effects of the something is missing here The values in the following table are examples of the rules regarding data type precedence.
I think the meaning of the explanation is that a programmer must use something like "CAST(sql_variant_value AS datatype)" or "CONVERT(datatype, sql_variant_value, style)" rather than "sql_variant_value" by itself.
|
|
|
|