DATALENGTH Versus COL_LENGTH to determine length of a string value. : DATALENGTH « System Functions « SQL Server / T-SQL Tutorial

SQL Server / T-SQL Tutorial
1. Query
2. Insert Delete Update
3. Table
4. Table Join
5. Data Types
6. Set Operations
7. Constraints
8. Subquery
9. Aggregate Functions
10. Date Functions
11. Math Functions
12. String Functions
13. Data Convert Functions
14. Analytical Functions
15. Sequence Indentity
16. View
17. Index
18. Cursor
19. Database
20. Transact SQL
21. Procedure Function
22. Trigger
23. Transaction
24. XML
25. System Functions
26. System Settings
27. System Tables Views
28. User Role
29. CLR
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL Server / T-SQL Tutorial » System Functions » DATALENGTH 
25. 7. 4. DATALENGTH Versus COL_LENGTH to determine length of a string value.
5>
6CREATE TABLE Composer (
7>      Composer_ID    integer  NOT NULL PRIMARY KEY,
8>      Composer      varchar(40)
9)
10> GO
1INSERT into Composer VALUES(100,"John")
2INSERT into Composer VALUES(101,"Jade")
3INSERT into Composer VALUES(102,"Queen")
4INSERT into Composer VALUES(103,"Leppard")
5INSERT into Composer VALUES(104,"Brooks")
6INSERT into Composer VALUES(105,"Raye")
7INSERT into Composer VALUES(106,"Street")
8INSERT into Composer VALUES(107,"Chicago")
9INSERT into Composer VALUES(108,"Outfield")
10INSERT into Composer VALUES(109,"REO")
11INSERT into Composer VALUES(110,"Cars")
12INSERT into Composer VALUES(111,"Rick")
13INSERT into Composer VALUES(112,"Genesis")
14INSERT into Composer VALUES(113,"Pat")
15INSERT into Composer VALUES(114,"Tears")
16INSERT into Composer VALUES(115,"Mode")
17INSERT into Composer VALUES(116,"Eagles")
18> GO

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)
1>
2SELECT Composer,DATALENGTH(Composer"Actual_Width",
3>               COL_LENGTH('Composer','Composer')"Defined_Width"
4> FROM composer
5> ORDER BY DATALENGTH(Composer)
6> GO
Composer                                 Actual_Width Defined_Width
---------------------------------------- ------------ -------------
REO                                                 3            40
Pat                                                 3            40
Mode                                                4            40
Cars                                                4            40
Rick                                                4            40
John                                                4            40
Jade                                                4            40
Raye                                                4            40
Queen                                               5            40
Tears                                               5            40
Eagles                                              6            40
Street                                              6            40
Brooks                                              6            40
Chicago                                             7            40
Leppard                                             7            40
Genesis                                             7            40
Outfield                                            8            40

(17 rows affected)
1>
2> drop table Composer;
3> GO
25. 7. DATALENGTH
25. 7. 1. Using DATALENGTH to determine length of a string value.
25. 7. 2. The DATALENGTH() function returns the number of bytes used to manage a value.
25. 7. 3. SELECT DATALENGTH(@Value2)
25. 7. 4. DATALENGTH Versus COL_LENGTH to determine length of a string value.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.