SQL Server Performance

Getting error message when executing a case when query

Discussion in 'SQL Server 2005 General Developer Questions' started by washingtondcmiss, Mar 1, 2011.

  1. washingtondcmiss New Member

    I am trying to transpose data from a view into a different format. The current data is not taking into account the year, only the month. The query I wrote is below and is failing to execute. The columns have a prefix e.g v2.sales_boundary_level is QL Chair v2.sales_boundary_level. How can i modify this query?select v2
    .Sales_Boundary_Level ,v2
    .Territory ,v2
    .Region ,v2
    .Area ,v2
    .Division ,v2
    .ProductID ,
    sum(case when v2.months = '2010, Month 1' then v2.value else 0 end) as Jan_Plan,
    sum(case when v2.months = '2010, Month 2' then v2.value else 0 end) as Feb_Plan,
    sum(case when v2.months = '2010, Month 3' then v2.value else 0 end) as Mar_Plan,
    sum(case when v2.months = '2010, Month 4' then v2.value else 0 end) as Apr_Plan,
    sum(case when v2.months = '2010, Month 5' then v2.value else 0 end) as May_Plan,
    sum(case when v2.months = '2010, Month 6' then v2.value else 0 end) as Jun_Plan,
    sum(case when v2.months = '2010, Month 7' then v2.value else 0 end) as Jul_Plan,
    sum(case when v2.months = '2010, Month 8' then v2.value else 0 end) as Aug_Plan,
    sum(case when v2.months = '2010, Month 9' then v2.value else 0 end) as Sep_Plan,
    sum(case when v2.months = '2010, Month 10' then v2.value else 0 end) as Oct_Plan,
    sum(case when v2.months = '2010, Month 11' then v2.value else 0 end) as Nov_Plan,
    sum(case when v2.months = '2010, Month 12' then v2.value else 0 end) as Dec_Planfrom
    dbo.view name
    where v2.Months like '2010%'group
    by v2.Sales_Boundary_Level ,v2
    .Territory ,v2
    .Region ,v2
    .Area ,v2
    .Division ,v2
    .ProductID
  2. FrankKalis Moderator

    Welcome to the forum!
    Not sure if you really have an object named dbo.view, but view is a reserved keyword. Try putting dbo.[view] into square brackets. Also, you have given dbo.view the alias name, but anywhere else you are using the alias v2.

Share This Page