Back to all blogs3 min read
How to check number of bytes used by a variable in SQL Server?
To check bytes used by a variable in SQL Server, you can use DATALENGTH function.
Ankush Jain
Lead Software Engineer (VP) | Software Architect
Published Nov 12, 2018Updated Nov 24, 2026
To check bytes used by a variable in SQL Server, you can use DATALENGTH function.
DECLARE @temp NVARCHAR(MAX)SET @temp = N'化字'SELECT DATALENGTH(@temp)This will display the number of bytes used @temp variable to represent a character or expression.