Problem to identify values in a case statement.

Hi Friends,
Total number of records in my report should be divided by 5 and to be alloted into 5 grades in Grade column.
This is what I have done so far in my report with following layout.
S.No - Col A - Col B - Col C - Grade ( Colums A,B,C will be hidden in Report)
*****Column C will have only 5 values at max ( 0.0, 0.2, 0.4, 0.6, 0.8).The below example is for 6 records in a report.The same will be applied for 7,8,9,10 records.
In column A: MAX(cast(RCOUNT(1) AS DOUBLE))/5 ( Ex : 6/5 = 1.2)
In Column B: Truncate(MAX(cast (RCOUNT(1) as double)/5), 0) ( Ex : 6/5 = 1.0)
In Column C: Col A- Col B ( EX:1.2 - 1.0 =0.2)
(MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0))
Now In Grade coulum I want to use this column C to Grade the records with case statements in it.
I am trying to use the following case statement for Grade Coulmn
Case
when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.0 then .........
when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.2 then .............
when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.4 then .............
when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.6 then ........
when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.8 then .....
end
Case statement works gud for 0.0 but not for other 4 values.
It is unable to identify other 4values.
Please tell me, how can I make case statement work for all values in above scenario.
Thanks in Advance,
Varsha.
Edited by: Varsha on Nov 28, 2010 6:23 PM

In column A: MAX(cast(RCOUNT(1) AS DOUBLE))/5 ( Ex : 6/5 = 1.2)
In Column B: Truncate(MAX(cast (RCOUNT(1) as double)/5), 0) ( Ex : 6/5 = 1.0)
In Column C: Col A- Col B ( EX:1.2 - 1.0 =0.2)
(MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0))Change the formula a bit by adding the by dim value for the MAX column.
Column A: MAX(cast(RCOUNT(1) AS DOUBLE) by DimTable.Column)/5
Column B: Truncate(MAX(cast (RCOUNT(1) as double) by DimTable.Column)/5, 0)
Column C: MAX(cast(RCOUNT(1) AS DOUBLE) by DimTable.Column)/5 - Truncate(MAX(cast (RCOUNT(1) as double) by DimTable.Column)/5, 0)
now write a case statement on top column c, based on your logic every 5th record will have a value 0.0
Note: Dimtable.column is the table.column for which the row count is taken.
Thanks,
Vino

Similar Messages

  • Problem in using aggregate functions inside case statement

    Hi All,
    I am facing problem while using aggregate functions inside case statement.
    CASE WHEN PSTYPE='S' THEN MAX(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) ELSE SUM(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) END,
    how can I achieve above requirement ? Con anyone help me.
    Thanks and Regards
    DG

    Hi All,
    Below is my query:
            SELECT
            CASE WHEN p_reportid IN ('POS_RV_SN','POS_PB') THEN POS.PACCT
            ELSE POS.PACCT || '-' || DECODE(POS.SYSTEMCODE,'GMI1','1', 'GMI2','2', 'GMI3','4', 'GMI4','3', '0') ||POS.PFIRM|| NVL(POS.POFFIC,'000') END,
            CASE WHEN p_reportid IN ('POS_RV_SN','POS_PB') THEN POS.PACCT||POS.PCUSIP||DECODE(POS.PBS,1,'+',2,'-')
            ELSE POS.PFIRM||POS.POFFIC||POS.PACCT||POS.PCUSIP||DECODE(POS.PBS,1,'+',2,'-') END,POS.SYSTEMCODE,CASE WHEN POS.PSTYPE='S' THEN POS.PSYMBL ELSE POS.PFC END,POS.PEXCH||DECODE(POS.PSUBEX,'<NULL>',''),
            POS.PCURSY,
            CASE WHEN POS.PSBCUS IS NULL THEN SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) ELSE POS.PSBCUS || SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) END ,
            NVL(POS.PSUBTY,'F') ,POS.PSTRIK,*SUM(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) ,SUM(DECODE(POS.PBS,2,ABS(POS.PPRTQ),0))* ,
            POS.PCLOSE,SUM(POS.PMKVAL) ,
            TO_CHAR(CASE WHEN INSTR(POS.PUNDCP,'.') > 0 OR LENGTH(POS.PUNDCP) < 15 THEN POS.PUNDCP ELSE TO_CHAR(TO_NUMBER(POS.PUNDCP) / 100000000) END),
            POS.UBS_ID,POS.BBG_EXCHANGE_CODE,POS.BBG_TICKER ,POS.BBG_YELLOW_KEY,POS.PPCNTY,POS.PMULTF,TO_CHAR(POS.BUSINESS_DATE,'YYYYMMDD'),
            POS.SOURCE_GMI_LIB,
            --DECODE(POS.SYSTEMCODE,'GMI1','euro','GMI2','namr','GMI3','aust','GMI4','asia','POWERBASE','aust','SINACOR','namr',POS.SYSTEMCODE),
            DECODE(p_reportid,'RVPOS_SING','euro','RVPOS_AUSTDOM','aust','RVPOS_AUSTEOD','euro','RVPOS_GLBLAPAC','asia','POS_RV_SN','namr','POS_PB','aust',POS.SYSTEMCODE),
            POS.RIC,
            CASE WHEN PSUBTY = 'S' THEN POS.TYPE ELSE NULL END,
            DECODE(POS.UBS_ID,NULL,POS.PCUSP2,POS.ISIN),POS.UNDERLYING_BBG_TICKER,POS.UNDERLYING_BBG_EXCHANGE,POS.PRODUCT_CLASSIFICATION,
            CASE WHEN PSUBTY = 'S' THEN POS.PSDSC2 ELSE NULL END,
            CASE WHEN PSUBTY = 'S' THEN C.SSDSC3 ELSE NULL END,
            NVL(C.SSECID,POS.PCUSIP),
            NULL,
            POS.PYSTMV,
            POS.PMINIT,
            POS.PEXPDT,
            CASE WHEN POS.PSUBTY='S' THEN  SUBSTR(C.ZDATA2,77,1) ELSE NULL END,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL
            FROM POSITIONS_WRK POS LEFT OUTER JOIN
            (SELECT * FROM CDS_PRODUCTS CP INNER JOIN FUTURE_MASTER FM ON
            (CP.STRXCH=FM.ZEXCH AND CP.SFC=FM.ZFC AND CP.BUSINESS_DATE = FM.BUSINESS_DATE )) C ON POS.PCUSIP = C.SCUSIP
            AND NVL(POS.PCUSP2,'X') = NVL(C.SCUSP2,'X')
            WHERE
            POS.PEXCH NOT IN ('A1','A2','A3','B1','B3','C2','D1','H1','K1','L1','M1','M3','P1','S1')
            AND (POS.PSBCUS IS NOT NULL OR POS.PCTYM IS NOT NULL OR POS.PSTYPE ='S')
            AND POS.BUSINESS_DATE = run_date_char
            GROUP BY
            POS.UBS_ID,POS.SYSTEMCODE,POS.RECIPIENTCODE,POS.BUSINESS_DATE,POS.PACCT,POS.PFIRM,POS.POFFIC,POS.PCUSIP,POS.PBS,CASE WHEN POS.PSTYPE='S' THEN POS.PSYMBL ELSE POS.PFC END,
            POS.PEXCH,POS.PSUBEX,POS.PCURSY,
            CASE WHEN POS.PSBCUS IS NULL THEN SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) ELSE POS.PSBCUS || SUBSTR(POS.PCTYM,5,2)  || SUBSTR(POS.PCTYM,1,4) END,
            NVL(POS.PSUBTY,'F') ,POS.PSTRIK,POS.PCLOSE,TO_CHAR(CASE WHEN INSTR(POS.PUNDCP,'.') > 0 OR LENGTH(POS.PUNDCP) < 15 THEN POS.PUNDCP ELSE TO_CHAR(TO_NUMBER(POS.PUNDCP) / 100000000) END),
            POS.BBG_EXCHANGE_CODE,POS.BBG_TICKER,POS.BBG_YELLOW_KEY,POS.PPCNTY,POS.PMULTF,POS.PSUBTY,POS.SOURCE_GMI_LIB,RIC,
            CASE WHEN PSUBTY = 'S' THEN POS.TYPE ELSE NULL END,
            DECODE(POS.UBS_ID,NULL,POS.PCUSP2,POS.ISIN),POS.UNDERLYING_BBG_TICKER,POS.UNDERLYING_BBG_EXCHANGE,POS.PRODUCT_CLASSIFICATION,
            CASE WHEN PSUBTY = 'S' THEN POS.PSDSC2 ELSE NULL END,
            CASE WHEN PSUBTY = 'S' THEN C.SSDSC3 ELSE NULL END,
            NVL(C.SSECID,POS.PCUSIP),
            POS.PYSTMV,
            POS.PMINIT,
            POS.PEXPDT,
            CASE WHEN PSUBTY = 'S'  THEN  SUBSTR(C.ZDATA2,77,1) ELSE NULL END;Now, could you plz help me in replacing the bold text in the query with the requirement.
    Thanks and Rgds
    DG
    Edited by: BluShadow on 16-May-2011 09:39
    added {noformat}{noformat} tags.  Please read: {message:id=9360002} for details on how to post code/data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Assigning value inside a case statement

    Hi friends
    iam using the below code and can any one tell me why even after assigning the value in the case statement it coming out of it.
    code
       data :
          p1(1) type n.
          case p1.
            when '0'.
              write 'sunday'.
            p1 = 1.
            when '1'.
              write 'monday'.
             p1 = 2.
            when others.
              write 'invalid day'.
         endcase.
    output.
       sunday
    can any one tell me why it is coming out of the case statement even iam assigning p1 = 1

    This is happening b'cause u have already in the when clause where u r setting the value of the variable that is controlling ur case..endcase statement.To meet ur requirement u need to trigger the case..endcase statement again as shown below:
    data :
    p1(1) type n.
    do 3 times.
    case p1.
    when '0'.
    write 'sunday'.
    p1 = 1.
    when '1'.
    write 'monday'.
    p1 = 2.
    when others.
    write 'invalid day'.
    endcase.
    enddo.

  • Re : Multiple values resut of CASE statement

    Hello All,
    Hope all is well. I was trying to basically return multiple values if a certain value 'X' was passed. for example,
    select
    case T1.C1
    when 'X' then ('XX','YY')
    else T1.C1
    end
    from T1
    but I am getting error. I am unable to figure out as to how do you get multiple values out of a single value in SQL. I will then be passing this multiple values as filter in where clause. For example,
    where ('XX','YY') in T2.C1
    Thanks in advance and let me know if I have missed on something.
    - Sam

    Hello Frank,
    Thanks for the response. You are correct , when value happens to be 'X' then I want to pass ('XX','YY') ( result of sub query) to the outer query. In essense, I want to pass multiple values to the outer query when a specific value is 'X'.
    For Example,
    I want query to be
    select T1.C1,T1.C2
    from T1
    where T1.C1 in ('XX','YY') // When the value of T2.C1 happens to be 'X'
    Let me know if I am clear here ..... The query throws no syntax error but does not return any data ...when there is data for T1.C1 in ('XX','YY') in DB. If I ran the query as is as posted above , query does return data but when it is ran as sub query as mentioned in previous posts , the query does not return any data !!!! ..thats where I am puzzled.
    Thanks again,
    Sam
    Edited by: user588790 on Jan 29, 2009 12:38 PM

  • Problem with building array inside a case statement

    I have a problem with my build array.
    Iam trying to construct a build array when ever I see a new element in my parent array during run time.
    Using shift registers, search array and If- case structure, inside a while loop. Iam implementing this logic (I dont want to use Event structure).
    Iam able to achieve most part of it, but have a problem with the first element. Except the first element of my parrent array, every thing is appending in to the build array. Can any one look at my vi and suggest me what Iam doing wrong here.
    Thank you
    Attachments:
    debug.vi ‏12 KB

    I think you need to replace the tunnels (carrying the array) in the for loop with a shift register.
    Lynn

  • Wildcard value in case statement

    Hi,
     How would I use a wildcard value in my case statement. I evaluate a string value of numbers and try to do this "1234***" but it doesn't work. "***" represents any 3 number. 
    Please advise.
    Thanks
    dphan128

    You could mark one of the cases as "Default", and that case will execute when no others match. If you want to explicitly run that case only if the first 4 numbers are "1234", then you need to pre-process the string.
    See here for the same exact question.

  • Using Field/Column Date Value In Case Statement

    I have code that the first part works (the part that evaluates null). However, it appears the second part doesn't work. The error I get is:
    Data Value out of range
    Can you use the a table column value in a Case statement? What I'm trying to do is: where all mbr06..values are 12/31/9999, then null; if mbr06.. values are equal to or less than today's date, then put the value in mbr02.mbr02_cancel_proc_date..
    Note, the table MBR02 does have dates that go back as far as 11/17/1858..could that be an issue?
    Thanks for any assistance..
                cast((case
                when mbr06.mbr06_exp_date = to_date('31-dec-9999') then null
                when mbr06.mbr06_exp_date <= sysdate then mbr02.mbr02_cancel_proc_date

    The error is due to the CAST, not to the CASE.
    Cause: Value from cast operand is larger than cast target size.Post at least the whole cast ...
    Max
    http://oracleitalia.wordpress.com

  • Trying to use greater than in a case statement

    What is the correct way to write this case statement?
    Case
    F.NextOrder2
    > F.CutOff
    Then
    Else F.NextOrder2
    as NextOrder3

    You're missing END, e.g.
    CASE when F.NextOrder2 > F.CutOff then '' else cast(F.NextOrder2 as varchar(100)) end as NextOrder3
    All values in the CASE statement must be of the same data type.
    See this blog post why
    SQL Server Case/When Data Type problems
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth
    Naomi Nosonovsky, Sr. Programmer-Analyst
    My blog

  • Problem In Case Statement

    HI ALL,
    in the program,i need to display description based on condition type.
    so we used CASE statement as below in LOOP. ITS not working .
    could anyone please suggest if anything wrong in the following code.
    LOOP AT gt_mat.
           MOVE gt_mat-type  TO gt_final-type.
      Condition description
    CASE gt_mat-type  .
    when  'N'.
    move  'New'  to gt_final-condes.
    when  'B'.
    move 'Block'   to gt_final4-condes.
    ENDCASE.
    ENDLOOP.
    please let me know whats the problem i above code and how to solve.
    thanks in advance.

    Hi,
    The only solution for this could be to debug the program and check if the coresponding values are populated and available. You could also try to replace the CASE statement with a simple IF statement and check if its working.
    LOOP AT gt_mat.
    MOVE gt_mat-type TO gt_final-type.
    * Condition description
    IF gt_mat-type = 'N'.
    gt_final-condes = 'New'.
    elseif gt_mat-type = 'B'.
    gt_final-condes ='Block'.
    append gt_final.
    clear gt_final.
    ENDIF.
    ENDLOOP.
    Also make sure the case of the value in gt_mat-type matches with the condition
    Regards,
    Vikranth

  • Print out a column value only if another column has a specific value (CASE Statement)

    Hello all,
    I tried many hours to find a solution for the following request but wasn't successful. Maybe you could help me.
    I've using the already existing SQL Views in Microsoft Service Manager to do some basic reporting about my tickets.There is no closed date in the activity tickets so I decided to print out the lastmodified timestamp when the status is "closed".
    That's my query:
    SELECT DISTINCT
    dbo.DisplayStringView.DisplayName AS Status,
    CASE WHEN dbo.DisplayStringView.DisplayName = 'Closed' THEN dbo.DisplayStringView.LastModified ELSE 'NO CLOSED Date' END AS ClosedDate
    FROM dbo.MTV_System$WorkItem$Activity$ManualActivity LEFT OUTER JOIN
    dbo.DisplayStringView ON dbo.MTV_System$WorkItem$Activity$ManualActivity.Status_8895EC8D_2CBF_0D9D_E8EC_524DEFA00014 = dbo.DisplayStringView.LTStringId
    Unfortunatelly I'm not getting the value from dbo.DisplayStringView.LastModified. SQL outputs that it is not possible to convert the string to date/time.
    I think there is a problem with the CASE statement in combination with a value select.
    Any ideas how to print out a column value only if another column has a specific value?

    I think it is the other way if you want the missing date shown as a string.
    CASE
    WHEN
    dbo.DisplayStringView.DisplayName
    =
    'Closed'
    THEN
    Convert( varchar(10),dbo.DisplayStringView.LastModified
    , 101) ELSE
    'NO CLOSED Date'
    END
    AS
    ClosedDate 

  • Navigate Value Interaction - Case Statements

    Hi,
    I am having problems using the navigate value interaction feature in OBIEE. The columns I am using to navigate contain case statement bin filters, is it not possible to use value interaction on these type of fields?
    For example bin grouping are created in both reports and are identical but the interaction does not work
    . TIMESTAMPDIFF(SQL_TSI_MONTH,CURR... is between 0 and 6
    . TIMESTAMPDIFF(SQL_TSI_MONTH,CURR... is between 7 and 12
    Can anyone advise a workaround other than creating the column in the rpd.
    Thanks

    I gave a detailed decision in a similar topic Obiee Report Help

  • Update with case statement problem.

    Hi,
    I have this statement
    update tab_tr set col_rate =
      case
      when col_ern_type in ('031','035','036') then (1.5 * col_rate)
      when col_ern_type in ('041','045','046') then (2 * col_rate)
    end;this statement updated some 2 million rows in the table tab_tr. But the total count of rows for col_ern_type in ('031','035','036', '041','045','046') yeild only around 222642 rows.
    select count(*) from tab_tr where col_ern_type in ('031','035','036', '041','045','046');  --> 222642 rowswhat is the problem with the above update statement.
    Thank you,

    Hi,
    DBA_1976 wrote:
    ... I thought the case statement conditions are counted as the where condition. But ......A CASE expression just takes the place of some other expression, such as a literal, a function, or a column.
    For example, which rows do you think this should update?
    UPDATE  tab_tr
    SET     col_rate  = 100;It would update all rows, of course.
    How about this statement?
    UPDATE  tab_tr
    SET     col_rate  = column_x;Will it only change the rows where column_x are a certain value, or not NULL, or in any way depend on column_x? No, of course not. It will update all rows.
    How about this statement?
    UPDATE  tab_tr
    SET     col_rate  = function_y (col_ern_type);Will it only change the rows where the fucntion returns a certain value? Will it depend on the value in col_ern_type? No, of course not. It calls the function for each row, and whatever the function returns (even if the function returns NULL), that's what goes into col_rate on each row.
    A CASE expression is just something that you can substitute in place of any other expression, such as the literal 100, or the column column_x, or the function function_y in the statements above. Naturally, the value that gets put into col_rate will depend on what the CASE expression returns, but the behavior of the UPDATE statement as a whole will not.

  • CASE Statement in Where Condition with Multi Valued parameter in SSRS

    Hi All,
    I am little confused while using CASE statement in Where condition in SSRS. Below is my scenario:
    SELECT
    Logic here
    WHERE
    Date IN (@Date)AND
    (CASE
    WHEN NAME LIKE 'ABC%' THEN 'GROUP1'
    WHEN ID IN ('123456', '823423','74233784') THEN 'GROUP2'
    WHEN ABC_ID IS NULL THEN 'GROUP3'
    ELSE 'GROUP4'
    END ) IN (@GROUP)
    So above query uses WHERE condition with CASE statement from @GROUP parameter. I want to pass this parameter as multi- valued parameter and hence I have used CASE statement IN (@GROUP).
    For @Date one dataset will pass the available and default values and
    for @GROUP parameters, another dataset will pass the available and default values.
    But this is not working as expected. Please suggest me where I am making mistake in the query.
    Maruthu | http://sharepoint-works.blogspot.com

    Hi Maruthu,
    According to your description, I create a sample report in my local environment. It works as I expected. In your scenario, if the selected values from the Date parameter contains some of the Date field values, the selected values from the GROUP parameter
    contains some of GROUPS (‘GROUP1’,’GROUP2’,’GROUP3’,’GROUP4’) and the corresponding when statement is executed , then the dataset returns the corresponding values.
    In order to trouble shoot this issue, could you tell us what results are you get and what’s your desired results? If possible, you can post the sample data with sample dataset, then we can make further analysis and help you out.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Handling Exceptions with case statement - convert Exception to int value

    Hi,
    I'm developing a web app, with servlets.
    I'm catching Exceptions in my servlets, for example I would like a user to insert data into a form. If the data cannot be converted into a integer value a java.lang.NumberormatException is thrown.
    I would like to catch this and then create a message giving a more specific clue to what happened. Unfortunatly it's possible that other exceptions could be caught, so I want to be able to check which type of Exception has been caught.
    I started writing a getErrorMessage(int Code) class. The method has a case statement which just checks the code and return the appropriate message.
    This worked well for SQL exceptions as they provide a getErrorCode method. But I was wondering is there any way to convert other Exceptions such as
    java.lang.NumberormatException into an integer value?
    Cheers

    Exceptions have their types (classes) and messages (and maybe an embedded exception). That is, they have much richer internal status then an integer.
    Why should they be "converted" to integers?
    FLAME on
    Gone are the days of good old errno.
    FLAME off

  • Naming the evaluated case statement field with concatenating input variable value

    Hi,
    I am trying to add the input variable value to case statement evaluated field like below query:
    declare @Year varchar(4)
    select ProductCode,datepart(mm,Date) MonthValue,
      case when datepart(mm,Date) = 1 then sum(Price) else 0 END AS Jan+@Year,
      case when datepart(mm,Date) = 2 then sum(Price) else 0 END AS Feb+@Year,
      case when datepart(mm,Date) = 3 then sum(Price) else 0 END AS Mar+@Year,
      case when datepart(mm,Date) = 4 then sum(Price) else 0 END AS Apr+@Year,
      case when datepart(mm,Date) = 5 then sum(Price) else 0 END AS May+@Year,
      case when datepart(mm,Date) = 6 then sum(Price) else 0 END AS Jun+@Year,
      case when datepart(mm,Date) = 7 then sum(Price) else 0 END AS Jul+@Year,
      case when datepart(mm,Date) = 8 then sum(Price) else 0 END AS Aug+@Year,
      case when datepart(mm,Date) = 9 then sum(Price) else 0 END AS Sep+@Year,
      case when datepart(mm,Date) = 10 then sum(Price) else 0 END AS Oct+@Year,
      case when datepart(mm,Date) = 11 then sum(Price) else 0 END AS Nov+@Year,
      case when datepart(mm,Date) = 12 then sum(Price) else 0 END AS Dec+@Year
    from Sales_Imports where datepart(yyyy,Date) = @Year
    group by  ProductCode, datepart(mm,Date)
    Please help me any other way as this is not working...
    Thanks,
    Srini

    create table Sales_Imports (ProductCode int, Price int, [date] date)
    insert into Sales_Imports values
    (1,10,'1/1/2014'),(1,109,'2/1/2014'),(1,10,'1/1/2014'),(1,109,'12/1/2014'),
    (2,10,'1/1/2014'),(2,109,'2/1/2014'),(2,10,'10/1/2014'),(2,109,'12/1/2014')
    declare @Year varchar(4)='2014'
    DECLARE @MaxCount INT, @SQL NVARCHAR(max) ,@i INT;
    Set @MaxCount = 12 
    SET @i = 0;
    SET @SQL = '';
    WHILE @i < @MaxCount
    BEGIN
        SET @i = @i + 1;
        SELECT @SQL = @Sql + ', SUM(CASE WHEN datepart(mm,[Date]) = ' + cast(@i AS NVARCHAR(10)) + ' THEN  Price Else 0 END) AS ' +Left(DateName(month,Dateadd(month,@i-1,0)) ,3)+@Year
    END
    SET @SQL = N' SELECT  ProductCode, datepart(mm,Date) MonthValue ' + @SQL 
    + N' FROM  Sales_Imports
     where datepart(yyyy,Date) ='+ @Year + N'group by  ProductCode, datepart(mm,Date)
     Order by ProductCode, datepart(mm,Date)';
    --PRINT @SQL;
    execute (@SQL);
    --Or your original one
    declare @Year varchar(4)
    Set @Year ='2014'
    declare @SQL  Nvarchar(4000)
    SET @SQL=
    N' select ProductCode,datepart(mm,Date) MonthValue,
      case when datepart(mm,Date) = 1 then sum(Price) else 0 END AS [jan' +@year+'],
      case when datepart(mm,Date) = 2 then sum(Price) else 0 END AS [feb' +@year+'],
      case when datepart(mm,Date) = 3 then sum(Price) else 0 END AS [Mar'+@year+'],
      case when datepart(mm,Date) = 4 then sum(Price) else 0 END AS [Apr'+@year+'],
      case when datepart(mm,Date) = 5 then sum(Price) else 0 END AS [May'+@year+'],
      case when datepart(mm,Date) = 6 then sum(Price) else 0 END AS [june'+@year+'],
      case when datepart(mm,Date) = 7 then sum(Price) else 0 END AS [july'+@year+'],
      case when datepart(mm,Date) = 8 then sum(Price) else 0 END AS [Aug'+@year+'],
      case when datepart(mm,Date) = 9 then sum(Price) else 0 END AS [Sep'+@year+'],
      case when datepart(mm,Date) = 10 then sum(Price) else 0 END AS [Oct'+@year+'],
      case when datepart(mm,Date) = 11 then sum(Price) else 0 END AS [Nov'+@year+'],
      case when datepart(mm,Date) = 12 then sum(Price) else 0 END AS [Dec'+@year+']
    from Sales_Imports where datepart(yyyy,Date) = ' + @Year +N' group by  ProductCode, datepart(mm,Date)'
    --print @Query
    Execute (@SQL)
    drop table Sales_Imports

Maybe you are looking for

  • Exchange Server 2013 - Unattended mode recoverserver fails

    Re-installing CAS server. This is something I have done before without issue. In order to properly upgrade from Server 2012 to 2012 R2, I have actually deleted the VDisk, created a blank. Installed server 2012 R2, ran prerequisites and hit the Exchan

  • Invalid Column Name message in the subquery

    Hi All, I am receiving the invalid column name message in the subquery. Please help me if there is any work around or change in the query: Sample query: update table1 set table1.column1 = (Select column1 from (Select column1 from table2 where table1.

  • How to change a parameter with script

    Hi to All, Is it possible change to TRUE the Parameter "07_DICTIONARY_ACCESSIBILITY" with a script ? If Yes, how can perform this ? Thank You and Best Regards. Gaetano

  • IPhone 6: The iPhone could not be restored. An unknown error occurred (53)

    Hello, I have iPhone 6 and iTunes says while restoring: The iPhone could not be restored. An unknown error occurred (53) After this fail iPhone only invites to connect to iTunes and then restore. I tried DFU mode, I have last version of iTunes and OS

  • How do I open an iview in a FULL pop up window

    I am trying to open an iview in a new window, and I want to display this new window in full page. I tried "FULL_PAGE" in the drop down option for Height Type. But it didn't work. I know that you can display the pop window in a full screen mode in "Wi