Sometimes we look for simple information like difference between SQL Server built in functions LEN() and DATALENGTH().
DATALENGTH() returns length of string in bytes, including trailing spaces. LEN() returns length of string in characters excluding trailing spaces.
e.g.
Executing the below script returns the result as shown in below screenshot.
SELECTLEN('sqlserver'),LEN('sqlserver '),DATALENGTH('sqlserver'),DATALENGTH('sqlserver '),LEN(N'sqlserver'),LEN(N'sqlserver '),DATALENGTH(N'sqlserver'),DATALENGTH(N'sqlserver ')
-------------------------------------------------------------------------
Reference: DP (http://dptechnicalblog.blogspot.com/)
DATALENGTH() returns length of string in bytes, including trailing spaces. LEN() returns length of string in characters excluding trailing spaces.
e.g.
Executing the below script returns the result as shown in below screenshot.
SELECTLEN('sqlserver'),LEN('sqlserver '),DATALENGTH('sqlserver'),DATALENGTH('sqlserver '),LEN(N'sqlserver'),LEN(N'sqlserver '),DATALENGTH(N'sqlserver'),DATALENGTH(N'sqlserver ')
-------------------------------------------------------------------------
Reference: DP (http://dptechnicalblog.blogspot.com/)
No comments:
Post a Comment