How to change output format from Pivot solution

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NareshN
    New Member
    • Aug 2010
    • 45

    How to change output format from Pivot solution

    Hi,

    I am using following pivot to get the result but getting error
    Code:
    SELECT StartDate,[headCount] AS headCount 
    FROM 
    (SELECT StartDate, headCount
    FROM SAR_HeadCount ) ps
    PIVOT
    (
      headCount
      for StartDate IN
      ([headCount])
    ) AS pvt
    When i use select * from tableName i am getting following data
    Code:
         [B]StartDate[/B]                            [B]Headcount[/B]
          08/01/2010                              182
          08/08/2010                              176
          08/15/2010                              198
          08/15/2010                              192
    I want data like this
    Code:
           [B]08/01/2010   08/08/2010    08/15/2010   08/22/2010[/B]
             182             176             198             192
    datewise headCount.
    Last edited by Frinavale; Oct 4 '10, 03:44 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • NareshN
    New Member
    • Aug 2010
    • 45

    #2
    How to pass dynamic dates to stored procedure with pivot

    Hi All,

    How to pass dynamic dates to stroed procedure with pivot.i am getting error while running belwo stored procedure

    Msg 8114, Level 16, State 1, Procedure Sample, Line 3
    Error converting data type nvarchar to datetime.
    Msg 473, Level 16, State 1, Procedure Sample, Line 3
    The incorrect value "@date1" is supplied in the PIVOT operator.


    Code:
    create procedure Sample(@date1 datetime,@date2 datetime,@date3 datetime,@date4 datetime,@CampaignID int)
    AS
    SELECT 'Forecasted' AS HeadCount,
    [@date1] as date1
    FROM
     (SELECT * FROM SAR_HeadCount) AS SourceTable PIVOT
      (SUM(HeadCount) FOR StartDate IN ([@date1])) 
    AS PivotTable;
    Last edited by Frinavale; Oct 4 '10, 04:52 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Please post the C# or VB.NET code that you have implemented which uses this stored procedure since that is where the error is occurring.

      Also, what control are you using to display the data?

      -Frinny
      Last edited by Frinavale; Oct 4 '10, 05:09 PM.

      Comment

      Working...