Substring on NText data type

  • I am trying to create a view where define a field as the first 100 characters of an NText type field. I get the error message "Data type error in expression"

    Substring(NTEXT,1,100)

    Documentation says Substring is valid for NText field types.

     

    Any help?

     

  • try this

    Create

    table ntexttest (sno int, val ntext)

    Create View vw as

    select

    sno, Substring(val,1,100) as val from ntexttest

     

    It is working fine for me

  • What's wrong with LEFT(somentextval,100) ???

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • you can use Left function also, but it won't accept ntext datatype,

    you have to explicitly convert the datatype to character types

  • Yah... forgot that the NTEXT data type is being used... sorry.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

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