[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

SQL Query

Posted on 2010-04-09
7
Medium Priority
?
938 Views
Last Modified: 2012-05-09
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

0
Comment
Question by:Leo Torres
  • 4
  • 3
7 Comments
 
LVL 41

Expert Comment

by:ralmada
ID: 30221539
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
 
LVL 8

Author Comment

by:Leo Torres
ID: 30223234
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
 
LVL 41

Accepted Solution

by:
ralmada earned 1500 total points
ID: 30223752
so try explicitly declaring the length.
Convert(varchar(8000),CE.ExtendedDescriptionText) as Description1
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
LVL 8

Author Comment

by:Leo Torres
ID: 30224145
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
 
LVL 8

Author Closing Comment

by:Leo Torres
ID: 31712811
Got it my self.. thanks tho
0
 
LVL 41

Expert Comment

by:ralmada
ID: 30224530
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
 
LVL 8

Author Comment

by:Leo Torres
ID: 30224868
Thought about it later the table got created with SISS so I didn't think to go back and change it till now.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this article, we will show how to detach and attach a database and then show how to repair a corrupt database and attach it, If it has some errors. We will show how to detach and attach using SSMS or using T-SQL sentences.
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…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

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