SQL Datalength and Len differential usage

Source: Internet
Author: User

Len (string_expression) parameter: string to be evaluated

Len () function
The Len function returns the length of the value in the Text field.

SQL Len () syntax
Select Len (column_name) from table_name

We want to get the length of the value in the "City" column.

We use the following SQL statement:

Select Len (city) as lengthofaddress from persons


Returns the number of characters for the specified string expression, which does not contain trailing spaces.
bigint If the expression data type is varchar (max), nvarchar (max), or varbinary (max);
The ntext field cannot be evaluated


DATALENGTH (expression) parameter: An expression of any data type

Grammar
DATALENGTH (expression)

Parameters
Expression

An expression of any type.

return type
Int

Use ADVENTUREWORKS2008R2;
Go
Select length = datalength (name), name
From Production.Product
Order BY name;
Go

The


Returns the number of bytes used to represent any expression.
returns bigint if the expression data type is varchar (max), nvarchar (max), or varbinary (max) data type;
for varchar, varbinary, text, image, nvarchar, and ntext data types, datalength is especially useful because these data types can store variable-length data. The result of the www.111cn.net
null datalength is null.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.