Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2010
    Posts
    4

    Unanswered: Query Using Pivot Table

    Hello folks,

    I am using the below code using PIVOT table.
    Code:
    SELECT *
    FROM (
      SELECT
        T0.[CardCode],
            
        CASE MONTH(T0.[DocDate]) 
          WHEN 1 THEN 'January'
          WHEN 2 THEN 'February'
          WHEN 3 THEN 'March'
          WHEN 4 THEN 'April'
          WHEN 5 THEN 'May'
          WHEN 6 THEN 'June'
          WHEN 7 THEN 'July'
          WHEN 8 THEN 'August'
          WHEN 9 THEN 'September'
          WHEN 10 THEN 'October'
          WHEN 11 THEN 'November'
          WHEN 12 THEN 'December'
        END as [Month],
        T1.[Price],
        T1.[Quantity],
        T2.[BWeight1]
        
      FROM ORDR T0 
           INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry 
           INNER JOIN [dbo].[OITM] T2 ON T1.ItemCode = T2.ItemCode 
         ) As TableDate
    PIVOT (
          SUM(Price*Quantity)/(SUM(BWeight1*Quantity)/1000)
          FOR [Month] IN (
          [January],[February],[March],[April],
          [May],[June],[July],[August],
          [September],[October],[November],[December])
          ) As PivotTable
    But it is displaying error:[HTML1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '*'. 2). [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement 'Service Contracts' (OCTR) (s) could not be prepared.][/HTML]

    What am I doing wrong? Is the syntax wrong?

    Thanks & Regards
    K

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    haven't got a clue what you are doing wrong, but then again I rarely use SQL server
    ...presumably you want it moving to the SQL server section
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •