August 21, 2010 at 1:34 pm
Comments posted to this topic are about the item DATALENGTH
August 21, 2010 at 1:45 pm
August 23, 2010 at 12:27 am
It is a good question about the basics, but not a very original one. I believe this sort of question has already been asked multiple times.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
August 23, 2010 at 4:09 am
good one... thanks...:-)
August 23, 2010 at 4:36 am
I would have had to give it a little more consideration if the options had included 1,3 and 3,1.
August 23, 2010 at 4:47 am
da-zero (8/23/2010)
It is a good question about the basics, but not a very original one. I believe this sort of question has already been asked multiple times.
I'd say at least 10 times, and then some for a couple more gotchas. I don't mind anual review but monthly and more seems like a bit too much ofr my taste.
August 23, 2010 at 7:02 am
This question proves that what I am learning on QoTD is actually sticking. Thanks.
August 23, 2010 at 9:30 am
Interesting that this does not work the same way.
select datalength(convert(varchar, getdate(), 101))
August 23, 2010 at 9:56 am
At first I thought 3,1, but since that was not an option I came to my senses and realized that varchar does not adjust if the string is too big.
August 23, 2010 at 10:48 am
kevin.l.williams (8/23/2010)
Interesting that this does not work the same way.select datalength(convert(varchar, getdate(), 101))
See http://msdn.microsoft.com/en-us/library/aa258242(v=SQL.80).aspx.
When n is not specified with the CAST function, the default length is 30.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
August 23, 2010 at 10:49 am
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
August 23, 2010 at 11:00 am
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.
August 23, 2010 at 2:13 pm
Nice question, thanks!
I'm surprised after all the recent questions that were related that we still have ~25% answering this one incorrectly.
August 23, 2010 at 3:24 pm
Thanks for the question
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
August 24, 2010 at 3:42 am
Nice question on the basics and all the ensuing explanations - thanks
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply