SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 DATALENGTH and LEN()
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

ravilobo
Flowing Fount of Yak Knowledge

India
1184 Posts

Posted - 09/21/2005 :  05:44:00  Show Profile
What is the difference between len() and DATALENGTH. I tried both in a SELECT, both are returning the same value. Can someone give me an example?

------------------------
I think, therefore I am - Rene Descartes

madhivanan
Premature Yak Congratulator

India
22755 Posts

Posted - 09/21/2005 :  05:55:29  Show Profile  Send madhivanan a Yahoo! Message
Len will trim the data but DATALENGTH doesnt do it

Select Len('Test ')
Select DATALENGTH ('Test ')


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Arnold Fribble
Yak-finder General

United Kingdom
1961 Posts

Posted - 09/21/2005 :  05:58:28  Show Profile
DATALENGTH returns the length of the string in bytes, including trailing spaces. LEN returns the length in characters, excluding trailing spaces. For example,

SELECT
  LEN('string'),
  LEN('string   '),
  DATALENGTH('string'),
  DATALENGTH('string   '),
  LEN(N'string'),
  LEN(N'string   '),
  DATALENGTH(N'string'),
  DATALENGTH(N'string   ')

will return 6, 6, 6, 9, 6, 6, 12, 18
Go to Top of Page

ravilobo
Flowing Fount of Yak Knowledge

India
1184 Posts

Posted - 09/21/2005 :  11:55:28  Show Profile
Thank you guys! Solved my doubt.

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 09/21/2005 :  15:07:23  Show Profile
Added to Newbie Sticky

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210

Kristen
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000