Function Left and IsNull together

  • Hello,

    How can I combine function Left and IsNull together?

    I am getting "Argument data type text is invalid for argument 1 of left function."


      select    left(isNull(tableA.notes,''),25) as MyNotes from dbo.tableA

    Thank you,
    Vinay

  • The problem was not caused because you are using isnull and left together.   It was caused because your table is using the text data type.  Text data type should not be used.  It exists for backwards compatibility.  One of the problem with this data type is that string functions can not be used with it.  You can modify the code and cast it as varchar(max), but if you can modify the data type on the table, it would be better


    select  left(isNull(cast(tableA.notes as varchar(max)),''),25) as MyNotes from dbo.tableA

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Thank you Adi. 

    I can't change the column type. So this solution is fine for me. Insrtead of varchar(max) I only need max 25 characters.

    Vinay

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply