[Webinar] Streamline your web hosting managementRegister Today


Group By with Text field question

Posted on 2006-05-08
Medium Priority
Last Modified: 2011-01-05
I have a table named Case_Text with the following layout
(Note: This is a vendor table so changing the table layout is not an option)

ColumnName               Type      Length

company_id               CHAR      3
case_id                               INT                     10
case_text_seq              INT                    10
case_text                             TEXT      

the following are some sample records:

company_id   case_id    case_text_seq       case_text
BSG                1                1                     This is case issue 1
BSG                1                2                     This is case issue 2
BSG                2                1                     This is case 2 issue 1

I am tying to write a group by sql statement that will group by company_id and case_id.

my objecitve is to get a result that looks like the following:

company_id              case_id    Case_Text
BSG                          1            This is case issue 1

                                             This is case issue 2                          
BSG                          2           This is case 2 issue 1  

I'm getting the dreaded "The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

I guess I could try to cast the text field to nvarchar but the text field can have way over 4000 characters which is what I think the limit of nvarchar is.

I was thinking of maybe using a derived table but not sure how to do that

Any help/ideas would be greatly appreciated



Question by:johnnyg123
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 150 total points
ID: 16631974
Columns of type text, ntext, and image cannot be used in group_by_expression
LVL 20

Accepted Solution

Sirees earned 750 total points
ID: 16631979
LVL 28

Assisted Solution

imran_fast earned 600 total points
ID: 16636957
you have to limit it to 4000

select company_id, cast(cast_text as varchar(4000)) from yourtable group by company_id, cast(cast_text as varchar(4000))

Author Comment

ID: 16648651
Thanks to all the took the time to respond.....you verified the sinking feeling I had that waht I was trying to do can't be done the way I would like.


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question