July 10, 2012 at 10:05 pm
Comments posted to this topic are about the item String Length
Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]
July 10, 2012 at 10:36 pm
Nice Question 🙂
[font="Verdana"] There is no Wrong time to do a Right thing 🙂 [/font]
July 10, 2012 at 11:12 pm
Very good question.Refreshed the basics.
I was not sure about middle two but sure about first two(7,7) and last two(14,80).
So objective approach which I developed from Engineering Entrance Exam worked and got the right answer 😉
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
🙂
July 11, 2012 at 12:01 am
Nice one , thanks
Iulian
July 11, 2012 at 12:13 am
Great question, thanks!
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
July 11, 2012 at 1:34 am
I thought the 4th one would be 8 at first, but since 7, 7, 8, 8, 14, 80 wasn't an option had to go by a process of elimination to find the right answer! Slightly odd behaviour from nchar() there, I learned something...
July 11, 2012 at 1:37 am
This was removed by the editor as SPAM
July 11, 2012 at 2:43 am
Good question - thanks
-------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
I would never join a club that would allow me as a member - Groucho Marx
July 11, 2012 at 2:52 am
Nice & Easy
Thanks
July 11, 2012 at 3:05 am
paul.knibbs (7/11/2012)
Slightly odd behaviour from nchar() there, I learned something...
Hmmm, not sure why you this is strange behaviour for nchar. It is fixed length, so any shorter length string put into it has to be padded. And if you then concatenate another string, it will of course go after the original string (which includes the padding). If you don't want the padding to be in there, use LTRIM() (or use nvarchar instead of nchar, obviously).
In my opinion, it is LEN() that has the strange behaviour here, because it returns the length of the padded version of the string instead of the length of the string itself. This almost caused me to give the wrong answer - but I recalled just in time the number of times I have already been bitten by this strange behaviour of LEN().
Thanks for a good question, Kenneth!
July 11, 2012 at 3:13 am
Hugo Kornelis (7/11/2012)
In my opinion, it is LEN() that has the strange behaviour here, because it returns the length of the padded version of the string instead of the length of the string itself.
Well, it's strange behaviour of LEN() when you provide it with an NCHAR parameter, which is what I sort of meant but failed to express in any comprehensible manner... 🙂
July 11, 2012 at 4:17 am
Great question. Tests some basics that sometimes trips us up.
July 11, 2012 at 5:09 am
Nice one. I learned some new stuff today. 🙂
July 11, 2012 at 6:21 am
Why does datalength of nchar(40) give 80?!?? That really threw me.
Thanks!
July 11, 2012 at 6:25 am
IowaDave (7/11/2012)
Why does datalength of nchar(40) give 80?!?? That really threw me.Thanks!
Because the "n" means the string is Unicode, so it has two bytes per character; DATALENGTH returns the actual length of the storage used for the field. 2 bytes per character * 40 characters = 80 bytes.
Viewing 15 posts - 1 through 15 (of 42 total)
You must be logged in to reply to this topic. Login to reply