The LENGTH() function

Informix® provides the LENGTH() function:

SELECT LENGTH("aaa"), LENGTH(col1) FROM table 

Microsoft™ SQL SERVER has a equivalent function called LEN().

Do not confuse LEN() with DATALEN(), which returns the data size used for storage (number of bytes).

Both Informix and SQL SERVER ignore trailing blanks when computing the length of a string.

Solution

You must adapt the SQL statements using LENGTH() and use the LEN() function.

Note:

If you create a user function in SQL SERVER as follows:

create function length(@s varchar(8000))
 returns integer
as
begin
   return len(@s)
end

You must qualify the function with the owner name:

SELECT dbo.length(col1) FROM table