SQL adaptation guide for SQL SERVER 2005, 2008, 2012, 2014, 2016 / Data manipulation |
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.
You must adapt the SQL statements using LENGTH() and use the LEN() function.
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