Mar 12, 2008 #1 sds814 Programmer Joined Feb 18, 2008 Messages 164 Location US Sorry for this question.. How do you determine the bytes of a string manually? For example, if the string is '1,2,3,4' how do you determine the bytes of that string? Thanks.
Sorry for this question.. How do you determine the bytes of a string manually? For example, if the string is '1,2,3,4' how do you determine the bytes of that string? Thanks.
Mar 12, 2008 #2 gmmastros Programmer Joined Feb 15, 2005 Messages 14,912 Location US There are a couple functions in SQL Server for determining the length of a string. There is Len and DataLength Len will tell you the number of characters (not bytes). DataLength will tell you the number of bytes needed to store the string. For example. Code: Declare @Temp VarChar(20) Set @Temp = '1,2,3,4' Select Len(@Temp), DataLength(@Temp) Declare @nTemp nVarChar(20) Set @nTemp = '1,2,3,4' Select Len(@nTemp), DataLength(@nTemp) Len will remove trailing spaces for you too (while it is determining length). Code: Declare @Temp VarChar(20) Set @Temp = '1,2,3,4 ' Select Len(@Temp), DataLength(@Temp) -George "The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom Upvote 0 Downvote
There are a couple functions in SQL Server for determining the length of a string. There is Len and DataLength Len will tell you the number of characters (not bytes). DataLength will tell you the number of bytes needed to store the string. For example. Code: Declare @Temp VarChar(20) Set @Temp = '1,2,3,4' Select Len(@Temp), DataLength(@Temp) Declare @nTemp nVarChar(20) Set @nTemp = '1,2,3,4' Select Len(@nTemp), DataLength(@nTemp) Len will remove trailing spaces for you too (while it is determining length). Code: Declare @Temp VarChar(20) Set @Temp = '1,2,3,4 ' Select Len(@Temp), DataLength(@Temp) -George "The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
Mar 12, 2008 Thread starter #3 sds814 Programmer Joined Feb 18, 2008 Messages 164 Location US Thanks for your reply George.. My question was more can you figure out the byte of a string calculating it by hand. Upvote 0 Downvote
Thanks for your reply George.. My question was more can you figure out the byte of a string calculating it by hand.
Mar 12, 2008 #4 gmmastros Programmer Joined Feb 15, 2005 Messages 14,912 Location US I'm afraid I still don't understand what you are asking. Can you please elaborate? -George "The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom Upvote 0 Downvote
I'm afraid I still don't understand what you are asking. Can you please elaborate? -George "The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
Mar 13, 2008 #5 Crowley16 Technical User Joined Jan 21, 2004 Messages 6,931 Location GB each character is 1 byte for varchar/char and 2 bytes for nvarchar/nchar count the characters you have and multiply by 1 or 2 accordingly... -------------------- Procrastinate Now! Upvote 0 Downvote
each character is 1 byte for varchar/char and 2 bytes for nvarchar/nchar count the characters you have and multiply by 1 or 2 accordingly... -------------------- Procrastinate Now!