SQL Query

The query below displays following error

Server Msg: 488, State: 42000, [Microsoft][SQL Server Native Client 10.0][SQL Server]
Pivot grouping columns must be comparable. The type of column "Description1" is "ntext", which is not comparable.


I tried
Convert(varchar,CE.ExtendedDescriptionText) as Description1
and tried
Convert(nvarchar,CE.ExtendedDescriptionText) as Description1
and
Convert(nvarchar(max),CE.ExtendedDescriptionText) as Description1 (this one displays even less information)

This will make it run, but then The entire Description does not display completely it gets truncated
;with CTE as (
SELECT     Left(Pd.CaseUPC,5)+right(Pd.CaseUPC,5) as ECaseUPC,
           P.ItemNumber , 
           PD.ProductNumber, 
           PD.CaseUPC, 
           CE.ExtendedDescriptionText as Description1,--CI.ItemCodeDesc as Description1 , 
           PD.Description2, 
           PD.Quantity, 
           PD.P_EFF_Date, 
           PD.P_END_Date, 
           PD.DIS_Date, 
           PD.Case_Weight, 
           PD.Case_CF, 
           PD.Case_Layer, 
           PD.Layer_Pallet, 
           PD.OD_DL, 
           PD.OD_DW, 
           PD.OD_DH, 
           PD.Pallet_DL, 
           PD.Pallet_DH, 
           PD.Shelf_Life, 
           PD.ProductLine,
           P.Replacement, 
           P.List AS ListPrice , 
           P.Contract AS Contract_Price, 
           P.Country AS CountryCode, 
           PD.P_End_Date AS C_End_Date, 
           PD.UnitsPerCase, 
           p.rn,
           Convert(Varchar,year(Cdate))+' Q'+Convert(Varchar,(Datename(q,CDate)))+' List' as QuarterList,
           Convert(Varchar,year(Cdate))+' Q'+Convert(Varchar,(Datename(q,CDate)))+' Contract' as QuarterContract
           

FROM         (SELECT     pt.PRODUCT_ID, PT.ItemNumber, pt.Replacement,AD.ProductNumber, AP.List, AP.Contract, AP.Country, AP.Cdate, ROW_NUMBER() OVER (PARTITION BY 
                                              PT.ItemNumber
                       ORDER BY Cdate DESC) rn
FROM         AccessData.dbo.Pricing AP INNER JOIN
                      AccessData.dbo.Product_Detail AD ON AP.PRODUCT_DETAIL_ID = AD.PRODUCT_DETAIL_ID LEFT JOIN
                      AccessData.dbo.Product PT ON PT.PRODUCT_ID = AD.PRODUCT_ID) AS P INNER JOIN
AccessData.dbo.Product_Detail PD ON PD.PRODUCT_ID = P.PRODUCT_ID AND PD.ProductNumber = P.ProductNumber left Join SQLMAS90.dbo.CI_Item CI on P.ItemNumber = CI.ItemCode
inner join SQLMAS90.dbo.CI_ExtendedDescription ce on ce.ExtendedDescriptionKey = ci.ExtendedDescriptionKey 
WHERE     P.rn = 1 AND pd.P_END_Date > getdate() 
)

Select     ECaseUPC,
           ItemNumber, 
           ProductNumber, 
           CaseUPC, 
           Description1 as Description1, 
           Description2, 
           Quantity, 
           P_EFF_Date, 
           P_END_Date, 
           DIS_Date, 
           Case_Weight, 
           Case_CF, 
           Case_Layer, 
           Layer_Pallet, 
           OD_DL, 
           OD_DW, 
           OD_DH, 
           Pallet_DL, 
           Pallet_DH, 
           Shelf_Life, 
           ProductLine,
           Replacement,
           COALESCE(MAX([2010 Q1 List]),0.00)         as [2010 Q1 List],
           COALESCE(MAX([2009 Q4 List]),0.00)         as [2009 Q4 List],
           COALESCE(MAX([2010 Q1 Contract]),0.00)         as [2010 Q1 Contact], 
           COALESCE(MAX([2009 Q4 Contract]),0.00)         as [2009 Q4 Contract]   
           
from CTE
PIVOT (SUM(ListPrice) FOR QuarterList IN ([2009 Q4 List],[2010 Q1 List])) uPvt
PIVOT (SUM(Contract_Price) FOR QuarterContract IN ([2009 Q4 Contract],[2010 Q1 Contract])) lPvt

Group by   ECaseUPC,
           ItemNumber, 
           ProductNumber, 
           CaseUPC, 
           Description1, 
           Description2, 
           Quantity, 
           P_EFF_Date, 
           P_END_Date, 
           DIS_Date, 
           Case_Weight, 
           Case_CF, 
           Case_Layer, 
           Layer_Pallet, 
           OD_DL, 
           OD_DW, 
           OD_DH, 
           Pallet_DL, 
           Pallet_DH, 
           Shelf_Life, 
           ProductLine,
           Replacement

Open in new window

LVL 8
Leo TorresSQL DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ralmadaCommented:
Convert(varchar,CE.ExtendedDescriptionText) as Description1 will only bring 30 characters by default
so you should try varchar(max).
However, check the maximum display length setting in Management Studio:

--> Tools / Option / Query Results / SQL Server / Results to Text /
Maximum number of characters displayed in each column

or

--> Tools / Option / Query Results / SQL Server / Results to Grid /
Maximum characters retrieved / Non XML Data


 
0
Leo TorresSQL DeveloperAuthor Commented:
No varchar(max) or nvarchar(max) return blank space
I went to thru tools menus but what changes am i making if any.. There is a picture below
Grid.JPG
0
ralmadaCommented:
so try explicitly declaring the length.
Convert(varchar(8000),CE.ExtendedDescriptionText) as Description1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Leo TorresSQL DeveloperAuthor Commented:
I tried that too It still chopped off the end..

I did figure it out tho I just when head and changed the Column type at the table level!

That was easy I should not even posted a questions for this tho... It must be Friday My brain is fried :)



Thanks dude..
0
Leo TorresSQL DeveloperAuthor Commented:
Got it my self.. thanks tho
0
ralmadaCommented:
I was going to suggest that actually as a next step. You should try to avoid using the TEXT or NTEXT datatypes and start  using Varchar(max) or NVarchar(max) instead.
0
Leo TorresSQL DeveloperAuthor Commented:
Thought about it later the table got created with SISS so I didn't think to go back and change it till now.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.