Group in text data column

  • I have a table as below:

    MEMBERID INT

    SEQUENCE INT

    NOTES TEXT

    I need a script to:

    select MEMBERID, max(SEQUENCE) and NOTES

    But, text data will not take group function.

    How to fix it?

  • No promises, try casting the NOTES column to varchar(max) in the select list, CAST(NOTES as VARCHAR(MAX)) as NOTES.

  • The real fix is to not use the text data type. It is deprecated. Use (n)varchar instead.

    A workaround to your immediate problem would be to CAST() your TEXT field as VARCHAR:

    select

    MEMBERID,

    max(SEQUENCE),

    cast(NOTES as varchar(128))

    from TestTextTable

    group by MEMBERID, cast(NOTES as varchar(128))

    You also need to determine if you want to group by NOTES as well (I assumed so in my query). If not, determine how you want it aggregrated.



    Twitter: @SQLife
    Email: sqlsalt(at)outlook(dot)com

  • Cast is working.

    Thanks

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

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