![]() |
|
|
By: Greg Robidoux | Read Comments (2) | Print Greg is the President of Edgewood Solutions and a co-founder of MSSQLTips.com. Related Tips: More |
|
Problem
There is sometimes a need to figure out the maximum space that is being used by a particular column in your database. You would initially think that the LEN() function would allow you to do this, but this function does not work on Text, NText or Image data types, so how do you figure out the length of a value in a column that has one of these data types?
Solution
In addition to the LEN() function, SQL Server also has a DATALENGTH() function. This function can be used on all data types in your table.
Here is an example of running these commands on an IMAGE data type using the LEN function:
SELECT name, LEN(packagedata)
FROM dbo.sysdtspackages
query results![]()
Here is an example of running these commands on an IMAGE data type using the DATALENGTH function:
SELECT name, DATALENGTH(packagedata)
FROM dbo.sysdtspackages
query results
If you wanted to find out the maximum length used for all of your records you could issue a command such as the following:
SELECT TOP 1 name, DATALENGTH(packagedata)
FROM dbo.sysdtspackages
ORDER BY 2 DESC
![]()
That is all there is to it. Another little function that you probably won't use often, but this is helpful to know it is there when you do need to use it.
Next Steps
| Share: | Share | Tweet |
|
![]() |
![]() |
Connect with MSSQLTips.com |
| Friday, April 11, 2008 - 1:43:11 AM - shaileshk | Read The Tip |
|
|
|
| Friday, April 11, 2008 - 9:55:00 AM - admin | Read The Tip |
|
Shaileshk, Thank you. That is certainly one approach. Thank you, |
|
|
privacy | disclaimer | copyright | advertise | about authors | contribute | feedback | giveaways | user groups Some names and products listed are the registered trademarks of their respective owners. Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com |
if you want to remove duplicate records with ntext,text and image datatype .please do the step as given into the link
http://www.codegroups.com/blog/index.php/deleting-duplicate-records-from-table-with-text-ntext-or-image-data-type/
I hope this is help !
Regards,
Shaileshk