Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Problem with text data type when using GROUP

Author  Topic 

Firebrand
Starting Member

24 Posts

Posted - 2010-07-05 : 11:00:03
Hello everyone,

the query below works fine until I introduce co.content, which is a column of the text data type. Then I get the error below which tells me that the data type cannot be sorted, which probably means GROUP. Do I need to change my data type or is there a way round this by changing the query?

Many thanks
----------
SELECT *
FROM
(SELECT
lo.LanguageOrderID AS OrderID,
lo.CountryID AS OrderCountryID,
lo.CountryLanguageID,
lo.LanguageID AS OrderLangID,
co.ContentID,
co.languageID,
co.CountryID,
co.CourseID,
co.content,
c.DomainURL,
lg.LanguageCode

FROM
( SELECT LanguageOrderID, CountryLanguageID, LanguageID
FROM tblLanguageOrder
GROUP BY LanguageOrderID, CountryLanguageID, LanguageID) AS l
CROSS JOIN
( SELECT LanguageID, CountryID, ContentID
FROM tblContent
GROUP BY LanguageID, CountryID, ContentID) AS t

LEFT JOIN tblLanguageOrder AS lo ON lo.LanguageID = l.LanguageID
LEFT JOIN tblContent AS co ON co.CountryID = t.CountryID
LEFT JOIN tblLanguages AS lg on lg.LanguageID = co.LanguageID
LEFT JOIN tblCountries AS c on c.CountryID = co.CountryID

WHERE
lo.CountryLanguageID = co.CountryID
AND lo.LanguageID = co.LanguageID
AND co.CourseId = 179
AND co.ContentTypeID = 11
AND lo.CountryID = 5
AND (co.ContentStatus = 1 OR co.ContentStatus = 2)
GROUP BY
co.ContentID, co.languageID, co.CountryID, co.content, co.languageID, co.CourseID, lo.LanguageOrderID, lo.CountryID, lo.CountryLanguageID, lo.LanguageID, lg.LanguageCode, c.DomainURL
)
AS dt
WHERE LanguageID = 5
ORDER BY OrderID

---------

Server: Msg 306, Level 16, State 2, Line 1
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-05 : 11:04:59
use cast(co.content as varchar(max)) in place of co.content

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Firebrand
Starting Member

24 Posts

Posted - 2010-07-05 : 11:17:44
quote:
Originally posted by madhivanan

use cast(co.content as varchar(max)) in place of co.content

Madhivanan

Failing to plan is Planning to fail



Nice one, although I'm thinking about changing the datatype?

Thanks again
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-05 : 11:22:53
Yes. Better change them as they wont be supported in future version of SQL Server

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Firebrand
Starting Member

24 Posts

Posted - 2010-07-05 : 11:34:11
quote:
Originally posted by madhivanan

Yes. Better change them as they wont be supported in future version of SQL Server

Madhivanan

Failing to plan is Planning to fail



Thanks for your help Madhivanan!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-06 : 02:19:12
quote:
Originally posted by Firebrand

quote:
Originally posted by madhivanan

Yes. Better change them as they wont be supported in future version of SQL Server

Madhivanan

Failing to plan is Planning to fail



Thanks for your help Madhivanan!


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -