Ntext

  • How to include a ntext column in the group by clause?

    Example comments is a ntext column

    select comments from tablename group by comments

    is giving a error message as

    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

     

     

     

  • This was removed by the editor as SPAM

  • Hi,

    I have tried with the below example...

    create table abc (a ntext)

    insert into abc values ('badbadabdada')

    select convert(nvarchar,a),count(*) from abc group by convert(nvarchar,a)

    and this works!!

     

    Regards,

    Indra Narayan.

  • Use caution here, you are not actually grouping by the entire ntext column, only the first 30 character! 

    Aunt Kathi Data Platform MVP
    Author of Expert T-SQL Window Functions
    Simple-Talk Editor

  • Thanks for your reply.

    I found if we query a ntext column, it does not result in full text, it cuts off in the middle.

    I understand if we assign it to a variable in an sp and then query, it would then give the full result.

    But I want to get the result by doing a select query as I am writing a view.

     

     

  • Are you on SQL Server 2005?  If so, try converting the ntext column to

    nvarchar(MAX).  Or, better yet, change the actual column to nvarchar(MAX) if you can.

    Aunt Kathi Data Platform MVP
    Author of Expert T-SQL Window Functions
    Simple-Talk Editor

  • I am using sqlserver 2000.

    I cant change the actual column, so I have to work on the query only.

Viewing 7 posts - 1 through 6 (of 6 total)

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