Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Problem with SQL Query

Author  Topic 

gpsk7
Starting Member

4 Posts

Posted - 2005-09-28 : 02:55:21
I am running the following querry to display the sum of length of 2 fields:

SELECT (datalength(field1) + datalength(field2))
FROM Table1

This query fails if it encounters a NULL value in any of the field. So is there any way around to check the NULL value in the fields before adding the lengths and if it founds NULL then add '0' to the length.

cheers.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-28 : 03:03:21
Try this

SELECT (datalength(IsNull(field1,'')) + datalength(IsNull(field2,'')))
FROM Table1


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -