|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, June 07, 2013 2:42 PM
Points: 1,662,
Visits: 1,710
|
|
kevin.l.williams (8/23/2010) Interesting that this does not work the same way.
select datalength(convert(varchar, getdate(), 101))
This is by design and has also been covered many times in recent QotDs. Forgetting to specify the size when declaring a local variable results in size defaulting to 1 while forgetting to specify the size when using convert - 30. Because the 101 format means mm/dd/yyyy, totalling 10 characters, the result of the query is 10 because the default 30 is greater than that.
Oleg
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 7:59 AM
Points: 2,808,
Visits: 1,129
|
|
Oleg Netchaev (8/23/2010)
This is by design and has also been covered many times in recent QotDs. Forgetting to specify the size when declaring a local variable results in size defaulting to 1 while forgetting to specify the size when using convert - 30. Because the 101 format means mm/dd/yyyy, totalling 10 characters, the result of the query is 10 because the default 30 is greater than that.
Oleg
Thanks.
I never like using implicit coding like this. It seems lazy and risky.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 9:45 AM
Points: 2,163,
Visits: 2,151
|
|
Nice question, thanks!
I'm surprised after all the recent questions that were related that we still have ~25% answering this one incorrectly.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Today @ 3:33 PM
Points: 18,858,
Visits: 12,443
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 2:18 AM
Points: 1,261,
Visits: 356
|
|
| Nice question on the basics and all the ensuing explanations - thanks
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Saturday, April 06, 2013 12:20 AM
Points: 649,
Visits: 263
|
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 8:52 AM
Points: 469,
Visits: 199
|
|
Great question and pick on the data types. It reminds that by default '1' is assigned to non-defined variable declaration for the char & varchar data types.
Thanks.
|
|
|
|