SQL Server Len() Function Vs. DataLength() Function
The LEN system function returns the number of characters of the specified string expression.
On the other hand, the DATALENGTH function returns the number of bytes used to represent any expression. Here’s a summary of the similarities and differences between the LEN() and DATALENGTH() system functions:
Case 1: With "Varchar" Data types:
DECLARE @Value varchar(20) SET @value = ‘Reddyz’ SELECT DATALENGTH(@value) SELECT LEN(@value)
Case 2: With "Nvarchar" Data types:
DECLARE @Value nvarchar(20) SET @value = ‘Reddyz’ SELECT DATALENGTH(@value) SELECT LEN(@value)
Case 3: With Integer Data types:
DECLARE @Value1 int, @value2 int SET @value1=2 SET @value2 =20000 SELECT DATALENGTH(@value1) SELECT LEN(@value1) SELECT DATALENGTH(@value2) SELECT LEN(@value2)
Case 4: With Extra Spaces:
DECLARE @value1 VARCHAR(25) SELECT @value1 = 'Reddyz ' SELECT @value1 AS COL_TEXT, LEN(@value1) AS LENGTH, DATALENGTH(@value1) AS DATA_LENGTH
Tuesday, 5 November 2013
What is the Difference between Len() and DataLength() Functions in SQL
How to Load data from SQL Server Tables, Create Relations and Manage Relationships in Power BI In this we will learn about : --Get Data...
Excel Formula to Calculate the Cumulative Sum or Running Total The Cumulative Sum will be formed by or resulting from accumulation or the ...
What is Conditional Column and How to Add it to a Table in Power BI Conditional Column is a New Column that will be Created based on a Con...
Creating a New Calculated Table from Existing Table in Power BI We can Create a New Table with Single Column using the " DISTINCT &qu...
Merging Two Queries or Tables in PowerBI Merge is a Technique of Combining Two Queries or Tables in Power BI. We can Merge Two Tables ba...
Appending One or More Queries or Tables in Power BI When we append the Two tables, rows will be Appended/Combined into one Table, one below...
What is Custom Column and How to Add it to a Table in Power BI A Custom Column is a new Column that we add to a Table based on the Custom ...
How to Get Data from a Input Source in PowerBI Desktop You can Connect to and Load Data from various Input sources in Power BI Desktop to ...
SSIS Package to Load Data from New Files and Reject the already Loaded Files Scenario : Suppose, We have a Source Folder where client wil...
Macro to Format or Convert the Data from the multiple columns to their respective Format 'To Convert the Number stored in a Text Forma...