Returns the number of bytes used to represent any expression
Example:IF EXISTS(SELECT name FROM sys.tables
WHERE name = 'test')DROP TABLE test;
GO
CREATE TABLE test
(
c1 varchar(5),
c2 char(5),
c3 nvarchar(5)
);
GO
INSERT INTO test VALUES ('1', '1','1'), ('22', '22', '22'),('333', '333', '333');
GOSELECT
DATALENGTH(c1) AS 'Varchar Column',
DATALENGTH(c2) AS 'Char Column',
DATALENGTH(c3) AS 'NVarChar Column'
FROM
test;
GO
Result:
Varchar Column Char Column NVarChar Column
1 5 22 5 4
3 5 6