Len() vs datalength() in SQL Server 2005

前端 未结 6 919
失恋的感觉
失恋的感觉 2020-12-08 19:36

Recently I faced a issue when using len() in a query to find out the length of a query, len() was not counting the trailing spaces in the value. Bu

6条回答
  •  死守一世寂寞
    2020-12-08 19:53

    Yes that's exactly what you must do. If you want to just get number of characters excluding blanks you would use LEN() function, while in all other cases DATALENGTH().

    Even LEN() documentation has an information that to get number of bytes to represent the extension you should use DATALENGTH()

    Here are the links to MSDN docs:

    LEN()

    DATALENGTH()

提交回复
热议问题