Sorting grouped values by month and year within chart

Hello
I have a really tough problem which I can't seam to figure out.
I have a table called SOLAR_RETURN which has 4 columns:
- ID
- USER_ID
- DATUM
- RETURN
On a page I have 3 links, one for showing the information from the database by day, month or year.
The hidden field :P25_DATE_FILTER is being set through the URL when clicking one of the 3 links.
I have a linechart with the following sql statement which pulls the correct data according to the value of :P25_DATE_FORMAT:
select null link, to_char("SOLAR_RETURN"."DATUM", :P25_DATE_FILTER) as label, max("SOLAR_RETURN"."RETURN") as value from "SOLAR_RETURN"
WHERE "SOLAR_RETURN"."USER_ID" = :USER_ID
AND to_char(DATUM, :P25_DATE_FILTER) = decode(:P25_DATE_FILTER,'YYYY',to_char(DATUM, 'YYYY'),'MM-YYYY',to_char(DATUM, 'MM-YYYY'),'DD-MM-YYYY',to_char(DATUM, 'DD-MM-YYYY'))
GROUP BY to_char(DATUM, :P25_DATE_FILTER)
Everything is working great, only the sorting is messed up. I need to sort it so that when :P25_DATE_FORMAT is set to DD-MM-YYYY it will be sorted by year desc, month desc, day desc. If the value would be MM-YYYY it would need to sort by year desc, month desc.
I have tried the following without succes:
ORDER BY to_char(DATUM, :P25_DATE_FILTER) ASC
--> This doesnt cut it since it sorts like this: (for example)
01-2010
02-2010
11-2009
12-2009
Vice versa for DESC
Is there any way that I can sort the grouped values by day, month and year seperately?
Thanks in advance!
Marc

Hi,
What is data type for column DATUM ?
If it is date did you try ORDER BY DATUM DESC ?
Br,Jari

Similar Messages

  • Hide days from WebElements component WECalendar (show only month and year)

    Dear expert,
    I'm using WebElements to replace standard InfoView parameter screen for my Crystal Reports. My question is:
    1. Is it possible to customize WebElements component: WECalendar so that we only see Month and Year, but not the Days (in other words to hide the days from the calendar).
    If not possible then is there any other WebElements component that i can use for this purpose?
    Because i only need to pass value of month and year selected by user when jumping to other report (using OpenDocument).
    2. When i looked at the code, i'm afraid the only way is by editing the HTML part that is marked with:
    // *** do not modify the code below
    Since there's no available variables for hiding the days in the section that can be modified:
    // *** the code below can be modified to change the formatting to the desired look and feel
    Below is some of the code of the WECalendar component:
    Function (stringvar ElementName, datevar ElementDefault, stringvar MonthDisplays, stringvar DayDisplays)
    // *** the code below can be modified to change the formatting to the desired look and feel
    // calendars use the stringvars below if nothing is entered into the WECalendar function for these parameters
    if DayDisplays="" then DayDisplays:= 'Su|Mo|Tu|We|Th|Fr|Sa'; // note that there must be two characters for each day...or use " " as in 'S |M |T |W |T |F |S ' 
    if MonthDisplays="" then MonthDisplays:= 'January|February|March|April|May|June|July|August|September|October|November|December';
    // the font below is for the month & year display in the calendar and can be modified
    stringvar headerfont:= WEFont('Verdana', 11, 'Navy', '', true, false,"","");
    // the font colour and size below can be modified...this is for the arrows that change the month or year of the calendar
    stringvar arrowfont:= WEFont('Arial', 10, 'Gray', '', false, false,"","");
    // these fonts for the calendar days must be a fixed width font such as Lucida Console or the calendar spacing will break
    stringvar datefont:= WEFont('Lucida Console', 8, 'Black', '', false, false,"","");
    stringvar daystringfont:= WEFont('Lucida Console', 8, 'Black', '', false, false,"underline","");
    stringvar weekendfont:= WEFont('Lucida Console', 8, 'Gray', '', false, false,"","");
    stringvar inputfont:= WEFont('Lucida Console', 8, 'Navy', 'Center', false, false,"","");
    // *** do not modify the code below
    Thank you very much.
    Kind regards,
    aswin
    Edited by: Aswin Setyawan Margono on Feb 2, 2011 5:16 PM

    hi Aswin,
    you can always modify any of the webelements controls or create your own if you're feeling adventurous. the "do not modify" is just a warning that the code below is not as customizable as the code above which is made to be easily changed.
    my recommendation for an easy win in your case though is to use the weSelectDuo control having years in the first of the select menus and the months in the second select menu.
    cheers,
    jamie

  • Month and Year on slider Movement.

    Hi,
    I am a newbie to XCelsius. I want to show and take the value of Month and Year (in format 'mmm-yy') up to last 12 months. But I am not able to convert the number which I get from slider to the Month and Year.
    Regards,
    Neel.
    Edited by: Neel Kulkarni on Jan 28, 2009 7:58 AM

    Hi Neel,
    I think you can do this with a vlookup. You would provide a set of cells which would provide the basis of the lookup and your slider would be the first arguement.
    The spreadsheet should look like this
    Item, Date, Formatted Date
    0, 29/01/2009, 01 2009
    0, 01/12/2008, 12 2008
    0, 01/11/2008, 11 2008
    0, 01/10/2008, 10 2008
    0, 01/09/2008, 09 2008
    0, 01/08/2008, 08 2008
    0, 01/07/2008, 07 2008
    0, 01/06/2008, 06 2008
    0, 01/05/2008, 05 2008
    0, 01/04/2008, 04 2008
    0, 01/03/2008, 03 2008
    0, 01/02/2008, 02 2008
    Once you have this (assuming from A1:C12) and with your slider value at D1 you can do a lookup
    =vlookup(D1, A1:C12, 3,false)
    and this will return appropriate value.
    The difficulty will be filling the date as Excel does not have a DateAdd function. The simplest approach would be to load this data via QaaWS or Live Office if you have that facility. If not you could write something like the following
    =DATE(IF((MONTH(TODAY())-A2)>0,YEAR(TODAY()), YEAR(TODAY())-1),IF((MONTH(TODAY())-A2)>=0,12,MONTH(TODAY())-A2),1)
    This is a bit buggy, as I have not time to debug it properly.
    You would then use the TEXT function to get the data in the format you want (you will have to extend this so that it converts 01 to Jan etc
    =TEXT(MONTH(B1), "00")&" "&TEXT(YEAR(B1), "00")
    Let me know how you get on
    Regards
    Alan

  • News articles grouped by month and year

    PHP and MySQL...
    Don't know if I am going to get an answer here, but I am looking for a bit of advice on how to handle grouping of news articles into months and each then into the respective year to make it easier for the user to navigate content. I am trying to acheive this effect:
    2012
    - July
    - June
    - March
    - January
    2011
    - December
    - October
    - April
    2010
    - November
    - You get the idea I hope
    I have set up MySQL to use a 'date' field called fld_articledate (formatted as YYYY-MM-DD). I need to structure my recordset query to select by year and group it, but then I also need to group by month relative to that year, but I have no idea of where to begin. So I guess my question is two-part:
    How do I group by year?
    How do I then group by month of that year?
    Once I have my queries sorted, I assume I'd print to page with  repeat and nested repeat regions!
    Thanks.
    Mat

    PHP and MySQL both have a lot of built in functions for working with dates.
    Here is a little code example from one of my projects that is similar to what you want to do. this example uses PDO, but the query is the same if you are using the older mysql extension. the last line builds an array of the result. You may not need this.Also note that the month and year are returned from the query using aliases (month, year); They could just as well be called "mymonth' and myyear, etc. The second to the last like formats the result for display.
    $sql=$dbh->prepare("SELECT DISTINCT EXTRACT(YEAR FROM(startdate)) AS year, EXTRACT(MONTH FROM (startdate)) as month FROM courses WHERE startdate > $currentdate order by startdate");
    $sql->execute();
    while ($monthorder = $sql->fetch(PDO::FETCH_ASSOC)){
    $month = $monthorder['month'];
    $year = $monthorder['year'];
    $monthtext = date('F Y', mktime(0,0,0,$month,1,$year));
    $monthlist[]=array('month'=>$month, 'year'=>$year);
    Since you want to link to articles, you then need a second query that will retrieve those details based on whatever month is selected. something like this:
    ("SELECT courses.course_id, title, startdate, enddate, highlight_photo FROM courses WHERE startdate > '$currentdate' AND EXTRACT(YEAR FROM (startdate)) = '$year' AND EXTRACT(MONTH FROM (startdate)) = '$month' ORDER BY startdate")

  • Table for Material Quantity and Value for particular month and year

    Hi All
    My requirement is that for a particular month and year I want to know the stock quantity and stock value for a particular material for a given plant.From which SAP table can I get this data as I want to fetch data for my Y report?
    Regards
    Satish Kumar

    Hi,
    You can use MB5B table as suggested earlier.also you can use:
    MBEW-VMKUM --> stock for previous month period
    MBEW-VJKUM --> stock for previous year period
    PLease view these links which migh tbe helpful to you:
    http://help.sap.com/saphelp_47x200/helpdata/en/39/55fee3bc6111d4b3960050dadf0791/content.htm
    TableStock
    Thanks
    Nisha

  • Returning  'Day' value based on month and year parameters

    Hi,
    Is there a code that would return an end of the month  Day value based on month and year parameters?
    For example if my parameters yield 9 or September for a month value and 08 or 2008 for the year value, can a formula generate a value of 30 (the last day of the given month in the specific year)?
    This way the formula would pick up the different last day of the month in February for the leap years.
    Thank you.
    Vic

    1. Open the formula workshop.
    2. From the Repository Custom Functions, under Crystal and then Date, RIGHT click on cdlastdayofmonth, click on ADD TO REPORT.
    3. Create a new formula, in the formula workshop, under FUNCTIONS, go down the list till you see "CUSTOM FUNCTIONS", expand that till you see cdlastdayofmonth.
    4. In your formula, type cdlastdayofmonth(currentdate)
    5. Save and close and display the formula in your report, you should see 11/30/2008.
    If you want just the day then modify the formula to:
    totext(day(cdlastdayofmonth(currentdate)),0,'','');
    since you have parameters for month and year, do this:
    totext(day(cdlastdayofmonth(date({?year},{?month},01))),0,'','');
    to give you the last day of the month.

  • How to save and month and year wise values

    Hi friends,
    in my ztable i have to enter values manually for month and year wise..
    so i have to create parameter for month and year how to create it.
    in my parameter month and year fields..
    once he given month and year  then he should enter values for fields..
    i have doubt how to give parameter for this...table..
    example: month: 1
                 year : 2007
    after that user enter values for following fields.
           kunnr
           name
           core values
           noncorevalues
    above fields user will enter values month wise ..
    once he enter the values for january it should save ...
    next he enter values for february and it will save..
    when ever he want to see the january month data how can he see..
    is there any logic for the above problem...

    Hai venkat,
    I am not totally clear with your question some how i understood. I give my opinion may be it ll help ful to you.
    In your ztable you want to enter the values for the fields kunnr, name, core values ,noncorevalues as per month. 
    As i say in your ztable add another field as  month  with other 4 fields. Provide the table maintenance for your table or else in se11 -> table display ->utilities -> table contents -> create entries is one way.
    If you proivided  maintenance for your table go to SM30. where you can manually enter values .
    <b>reward if useful</b>
    Regards,
    sunil kairam.

  • Sales report for current month and year a go month

    i could you please guide me builting report for current monthwise for current month and year a ago month
    report parameter month_year='06-2010'
    tables = sales and below are the table fields
    customer_id
    invoice_dt
    invoice_am
    thanks
    nhm

    Okay, Still you did not mention how you will pass value in report while generating.
    Anyway the query with UNION ALL will work. For Example.
    I am assuming that the parameter for date/month you will pass in range like 01-JUN-2010 to 30-JUN-2010
    SELECT customer_id, SUM(curr_value) curr_value, SUM(past_value) past_value
    FROM
    SELECT customer_id, NVL(SUM(invoice_amount),0) curr_value, 0 past_value
    FROM sales
    WHERE invoice_dt BETWEEN :P_FROM_DATE AND :P_TO_DATE  -- here P_FROM_DATE and P_TO_DATE will be the date range for current year as i showed above.
    AND  -- Any Condition goes here...
    GROUP BY customer_id
    UNION ALL
    SELECT customer_id, 0, NVL(SUM(invoice_amount),0)
    FROM sales
    WHERE invoice_dt BETWEEN ADD_MONTHS(:P_FROM_DATE,-12) AND ADD_MONTHS(:P_TO_DATE,-12) -- This add_months function for the previous year same month.
    AND -- Any condition goes here...
    GROUP BY customer_id
    GROUP BY customer_idNow using the above query you can design the tabular report as you showed the format.
    -Ammad
    Edited by: Ammad Ahmed on Jul 3, 2010 7:55 PM
    added GROUP BY

  • Display month and year in dropdown list on selection screen

    Hi
      Can anyone tell me how to display months and year in a dropdown list on a selection screen?
      also please tell me how to get the first and the last dates upon selecting the month and year on the dropdown list.
    Month: January Year:2007 . 
    After selecting the required month and year, the first date and last date i.e '01.01.2007 - 31.01.2007' should be displayed on the right side.
    Reward Points assured..
    thanks,
    Chetan

    Hi..,
    <b>
    Just copy, paste and execute this program !!</b>
    type-pools: vrm.
    parameters : p_month(2) type n as listbox visible length 10,
    p_year(4) type n as listbox visible length 10.
    DATA : W_DATE type d, w_ldate type d.
    initialization.
    perform user_drop_down_list_fordt.
    perform user_drop_down_list_foryr.
    start-of-selection.
    concatenate p_year p_month '01' into w_date.
    call function 'BKK_GET_MONTH_LASTDAY'
      exporting
        i_date        = w_date
    IMPORTING
       E_DATE        = w_ldate
    write /: w_date,w_ldate.
    build user_drop_down_list
    form user_drop_down_list_fordt.
    data: name type vrm_id,
    list type vrm_values,
    value like line of list.
    data: t_months type t247 occurs 0 with header line.
    clear list. refresh list.
    name = 'P_MONTH'.
    select * into  table t_months
    from t247 where spras eq 'EN'.
    sort t_months ascending by mnr.
    loop at t_months.
    clear value.
    value-key = t_months-mnr.
    value-text = t_months-ltx.
    append value to list.
    endloop.
    Set the values
    call function 'VRM_SET_VALUES'
    exporting
    id = name
    values = list.
    endform.
    for year...
    form user_drop_down_list_foryr.
    data: name type vrm_id,
    list type vrm_values,
    value like line of list.
    clear list. refresh list.
    name = 'P_YEAR'.
    do 9999 times.
    clear value.
    value-key = sy-index.
    append value to list.
    enddo.
    Set the values
    call function 'VRM_SET_VALUES'
    exporting
    id = name
    values = list.
    endform.
    <b>
    Hope this solves ur problem..</b>
    regards,
    sai ramesh

  • Selecting records based on month and year parameters

    Hi. I have a sql 2008 r2 stored procedure which needs modifying to return the data based on a start / end month and year.
    It's a large SP so I'll summarise - It accepts four parameters:
    @StartMonth NVARCHAR(10)
    @StartYear NVARCHAR(4)
    @EndMonth NVARCHAR(10)
    @EndYear NVARCHAR(4)
    The current WHERE clause is:
    WHERE ta.TimeByDay BETWEEN '01' + '-' + ltrim(LEFT(@StartMonth, 3)) + '-' + @StartYear
    AND convert(nvarchar,datediff(day, ta.TimeByDay, dateadd(month, 1, ta.TimeByDay))) + '-' + ltrim(LEFT(@EndMonth, 3)) + '-' + @EndYear
    Example of input parameters:
    @StartMonth = N'January',
    @StartYear = N'2014',
    @EndMonth = N'February',
    @EndYear = N'2014',
    Result:
    The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
    (1 row(s) affected)
    However it executes correctly if we do either of the following:
    1) Run the SQL direct in QA and type in January and February rather than passing in the Start/End Month parameters
    2) As you can see we use the following datediff call to get the number of days per month. IF I replace this with '28', or '31' for example the query also runs (oddly number 1 above then also runs by executing the SP):
    convert(nvarchar,datediff(day, ta.TimeByDay, dateadd(month, 1, ta.TimeByDay)))
    How do I update the WHERE clause to return records between a start/end month and year?
    I'm a day on this so any help appreciated.
    Thanks

    create function NthDayOfMonth (@year int, @month smallint, @weekday varchar(15), @nth smallint)
    returns datetime
    as
    begin
    declare @the_date datetime, @c_date datetime, @cth smallint
    set @cth = 0
    set @c_date = convert(varchar,@year)+'-'+convert(varchar,@month)+'-01'
    while month(@c_date) = @month
    begin
    if datename(weekday,@c_date) = @weekday set @cth = @cth + 1
    if @cth = @nth and datename(weekday,@c_date) = @weekday set @the_date = @c_date
    set @c_date = dateadd(day,1,@c_date)
    end
    return @the_date
    end
    go
    create function Dates(@date datetime)
    returns @table table
    now datetime,
    today datetime,
    Month_start datetime,
    Month_end datetime,
    Prev_Month_Start datetime,
    Prev_Month_End datetime,
    Week_Start datetime,
    Week_End datetime,
    Prev_Week_Start datetime,
    Prev_Week_End datetime,
    Quarter_Start datetime,
    Quarter_End datetime,
    Prev_Quarter_Start datetime,
    Prev_Quarter_End datetime,
    Year_Start datetime,
    Year_End datetime,
    Prev_Year_Start datetime,
    Prev_Year_End datetime,
    Month_End_TS datetime,
    Prev_Month_End_TS datetime,
    Week_End_TS datetime,
    Prev_Week_End_TS datetime,
    Quarter_End_TS datetime,
    Prev_Quarter_End_TS datetime,
    Year_End_TS datetime,
    Prev_Year_End_TS datetime,
    Year smallint,
    Month smallint,
    Day smallint,
    Month_Name varchar(15),
    Day_Name varchar(15),
    WD smallint
    as
    begin
    if @date IS NULL set @date = getdate()
    insert into @table
    select
    @date as now,
    convert(datetime,convert(varchar,@date,101)) as today,
    dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Month_Start,
    dateadd(day,-1,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))))) as Month_end,
    dateadd(month,-1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_start,
    dateadd(day,-1-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Prev_Month_End,
    dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_Start,
    dateadd(day,7-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_End,
    dateadd(day,-6-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_Start,
    dateadd(day,0-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_End,
    convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01') as quarter_start,
    dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01'))) as quarter_end,
    convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01') as prev_quarter_start,
    dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01'))) as prev_quarter_end,
    dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))) as Year_Start,
    dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Year_End,
    dateadd(year,-1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_Start,
    dateadd(year,-1,dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Prev_Year_End,
    dateadd(ms,-3,dateadd(day,0,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))))) as Month_End_Ts,
    dateadd(ms,-3,dateadd(day,-1-day(@date)+2,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_End_TS,
    dateadd(ms,-3,dateadd(day,8-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Week_End_TS,
    dateadd(ms,-3,dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Prev_Week_End_TS,
    dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01')))) as quarter_end_TS,
    dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01')))) as prev_quarter_end_TS,
    dateadd(ms,-3,dateadd(year,1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Year_End_TS,
    dateadd(ms,-3,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_End_TS,
    Year(@date) as Year,
    Month(@date) as Month,
    Day(@Date) as Day,
    datename(month,@Date) as Month_Name,
    datename(WEEKDAY,@date) as Day_Name,
    datepart(weekday,@date) as WD
    return
    end
    go
    create function Holidays(@year smallint)
    returns @table table
    date datetime,
    type varchar(10),
    name varchar(25)
    as
    begin
    insert into @table
    select convert(datetime,convert(varchar,@year)+'-01-01') as date,'Holiday' as type ,'New Years Day' as name UNION ALL
    select dbo.NthDayOfMonth(@year,2, 'Monday',3),'Holiday','Family Day' UNION ALL
    select dateadd(d,0-case when datepart(weekday,convert(varchar,@year)+'-05-25') in (1,2) then 5+datepart(weekday,convert(varchar,@year)+'-05-25') else datepart(weekday,convert(varchar,@year)+'-05-25')-1 end, convert(varchar,@year)+'-05-25') ,'Holiday','Victoria Day' UNION ALL
    select convert(varchar,@year)+'-01-07' ,'Holiday','Canada Day' UNION ALL
    select dbo.NthDayOfMonth(@year,8, 'Monday',1),'Holiday','Civic Holiday' UNION ALL
    select dbo.NthDayOfMonth(@year,9, 'Monday',1),'Holiday','Labour Day' UNION ALL
    select dbo.NthDayofMonth(@year,10,'Monday',2),'Holiday','Thanksgiving' UNION ALL
    select convert(varchar,@year)+'-11-11' ,'Holiday','Rememberance Day'UNION ALL
    select convert(varchar,@year)+'-12-25' ,'Holiday','Christmas Day' UNION ALL
    select convert(varchar,@year)+'-12-26' ,'Holiday','Boxing Day'
    update @table
    set date =
    case when name != 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
    when name != 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,1,date)
    when name = 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
    when name = 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,2,date)
    when name = 'Boxing Day' and datepart(weekday,date) = 2 then dateadd(day,1,date)
    else date
    end
    return
    end
    go
    Using these functions (in place of a calendar table) you could do something like this:
    DECLARE @forumTable TABLE (sales MONEY, saleDate DATE)
    INSERT INTO @forumTable (sales, saleDate)
    VALUES
    (123.45, '2014-01-05'),(678.90, '2014-01-06'),(111.21, '2014-01-07'),(314.15, '2014-01-08'),(161.71, '2014-01-09'),
    (819.20, '2014-02-05'),(212.22, '2014-02-06'),(324.25, '2014-02-07'),(262.72, '2014-02-08'),(829.30, '2014-02-09')
    SELECT SUM(f.sales), d.month_end
    FROM @forumTable f
    CROSS APPLY sandbox.dbo.dates(f.saleDate) d
    GROUP BY d.month_end

  • Pivot with Month and Year

    Hi all Thanks in Advance
    I need help in Pivoting Data
    SELECT ID,MONTH,COUNT FROM TABLE_PIVOT ORDER BY ID,MONTH
    ID     MONTH          COUNT
    10     10/01/2009     60
    10     11/01/2009     80
    10     12/01/2009     78
    10     01/01/2010     81
    10     02/01/2010     73
    10     03/01/2010     84
    10     04/01/2010     100
    10     05/01/2010     107
    10     06/01/2010     90
    10     07/01/2010     0
    10     08/01/2010     0
    10     09/01/2010     73
    20     10/01/2010     71
    20     11/01/2010     76
    20     12/01/2010     79
    20     01/01/2011     79
    20     02/01/2011     81
    20     03/01/2011     88
    20     04/01/2011     97
    20     05/01/2011     87
    20     06/01/2011     97I tried to pivot with below query
    SELECT ID,
    SUM(DECODE(to_char(month,'MM'),'01',count,0)) " Jan",
    SUM(DECODE(to_char(month,'MMYY'),'02',count,0)) Feb,
    SUM(DECODE(to_char(month,'MM'),'03',count,0)) Mar,
    SUM(DECODE(to_char(month,'MM'),'04',count,0)) Apr,
    SUM(DECODE(to_char(month,'MM'),'05',count,0)) May,
    SUM(DECODE(to_char(month,'MM'),'06',count,0)) June,
    SUM(DECODE(to_char(month,'MM'),'07',count,0)) July,
    SUM(DECODE(to_char(month,'MM'),'08',count,0)) August,
    SUM(DECODE(to_char(month,'MM'),'09',count,0)) September,
    SUM(DECODE(to_char(month,'MM'),'10',count,0)) October,
    SUM(DECODE(to_char(month,'MM'),'11',count,0)) November,
    SUM(DECODE(to_char(MONTH,'MM'),'12',count,0)) December
    FROM Table_PIVOT
    GROUP BY ID
    ORDER BY ID
    ID      Jan     FEB     MAR     APR     MAY     JUNE     JULY     AUGUST     SEPTEMBER     OCTOBER     NOVEMBER     DECEMBER
    10      81     0     84     100     107     90     0     0          73          60          80          78
    20      79     0     88     97     87     97     0     0          0          71          76          79I want output to display the column names with Month and Year like below
    ID     Oct-2009     Nov-2009     Dec-2009   Jan-2010  Feb-2010 ................... OCT-2010  NOV-2010 DEC-2010 JAN-2011 FEB-2011 ......
    10     60          80          78          81          73     ...................
    20                                                                    71           76          79     79          81
    CREATE TABLE "TABLE_PIVOT"
       (     "ID" NUMBER,
         "MONTH" DATE,
         "COUNT" NUMBER
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('10/01/2009','MM/DD/YYYY'),60);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('11/01/2009','MM/DD/YYYY'),80);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('12/01/2009','MM/DD/YYYY'),78);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('01/01/2010','MM/DD/YYYY'),81);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('02/01/2010','MM/DD/YYYY'),73);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('03/01/2010','MM/DD/YYYY'),84);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('04/01/2010','MM/DD/YYYY'),100);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('05/01/2010','MM/DD/YYYY'),107);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('06/01/2010','MM/DD/YYYY'),90);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('07/01/2010','MM/DD/YYYY'),0);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('08/01/2010','MM/DD/YYYY'),0);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (10,to_timestamp('09/01/2010','MM/DD/YYYY'),73);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (20,to_timestamp('10/01/2010','MM/DD/YYYY'),71);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (20,to_timestamp('11/01/2010','MM/DD/YYYY'),76);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (20,to_timestamp('12/01/2010','MM/DD/YYYY'),79);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (20,to_timestamp('01/01/2011','MM/DD/YYYY'),79);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (20,to_timestamp('02/01/2011','MM/DD/YYYY'),81);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (20,to_timestamp('03/01/2011','MM/DD/YYYY'),88);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (20,to_timestamp('04/01/2011','MM/DD/YYYY'),97);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (20,to_timestamp('05/01/2011','MM/DD/YYYY'),87);
    Insert into TABLE_PIVOT (ID,MONTH,COUNT) values (20,to_timestamp('06/01/2011','MM/DD/YYYY'),97);
    COMMIT;

    Hi,
    user1849 wrote:
    Any Sample code is appreciated
    I didn't see any solution for following one in your linklI think Centinul was specifically referring to:
    Help for a query to add columns
    but other links from
    SQL and PL/SQL FAQ
    may help you more.
    >
    Re: How to pipeline a function with a dynamic number of columns?
    Posted: May 9, 2006 2:58 PM in response to: Billy Verreynne Reply
    Interesting stuff! It's going to take me awhile to digest it.
    For what it's worth, I was trying to build a pivoting function that would take a MYTABLE table like this:
    YEAR CITY X Y
    2000 BAL 95 96
    2000 BOS 101 101
    2001 BAL 92 94
    2001 BOS 101 101
    2002 BAL 98 98
    2002 BOS 98 99
    2003 BAL 95 96
    2003 BOS 105 104
    and allow me to do something like:
    CREATE VIEW MYPIVOT
    AS
    SELECT *
    FROM TABLE (PIVOT(MYTABLE, [with other params]))
    and get the following view MYPIVOT on the table:
    YEAR BOS_X BOS_Y BAL_X BAL_Y
    2000 101 101 95 96
    2001 101 101 92 94
    2002 98 99 98 98
    2003 105 104 95 96
    Where the number of distinct CITY values will vary over time. I am able to build the query I need dynamically, but since the CITY data values in the original table change, the columns are not necessarily static from invocation to invocation. Therefore I didn't want to just create a view using the dynamic SQL once, because it may need to be created next time I need to access the view. I wanted to be able to access the pivoted data on demand.A pipelined function is your best bet for that.
    I couldn't do was be able to execute the query and treat it as a pipelined function, hence my original question.Sorry, I don't understand.
    I'll dig into the code above to see if it does what I wanted, but if someone has a better suggestion on how to approach this, I'd be interested in hearing it.A completely different approach is String Aggregation , where you would get output like this:
    YEAR  TXT
            BOS_X    BOS_Y    BAL_X    BAL_Y
    2000      101      101       95       96
    2001      101      101       92       94
    2002       98       99       98       98
    2003      105      104       95       96Note that this output contains 6 rows and 2 columns. On the first row, year is NULL and txt='  BOS_X    BOS_Y    BAL_X    BAL_Y'. You can do this is pure, static SQL, without knowing the number of cities in advance.

  • Fetching month and year from CV of Time dim

    Hi,
    I am working on BPC 7 MS version, SP3. I need to fetch Month and Year values from my Current View (i.e., %TIME_SET%) .... and if the month is AUG and year is Current I then want a logic to run... Is this possible??
    I have written the following code, and only if i hardcode the time (WHEN TIME IS 2009.AUG) the logic seems to work. But I want it to be dynamic
    *XDIM_MEMBERSET ACCOUNT=INC_REC_IN_AD
    *XDIM_MEMBERSET TIME=%YEAR%.AUG,%TIME_SET%
    *XDIM_MEMBERSET CATEGORY=ACTUAL
    *WHEN ACCOUNT
    *IS *
    *WHEN TIME.MONTHNUM
    *IS 8
    *FOR %YEAR%=%TIME_SET%.YEAR
    *FOR %MONTH%=AUG,SEP,OCT,NOV,DEC
    *REC(FACTOR=1/5,TIME="%YEAR%.%MONTH%",ACCOUNT="TEMPSTUDYEDU")
    *NEXT
    *NEXT
    *ENDWHEN
    *ENDWHEN
    *COMMIT
    Thanks,
    Prasanth.

    I think your formula is correc the %YEAR% is not a valid, Can you trap that and see what is being passed, you may also try to split the year out of %TIME%
    hope it helps.

  • Data element for Month and Year

    Hello All,
    Is there any data element which will have only Month and Year.
    I have to introduce this field in a table. It should have convesion exits also.
    Ex: If i give 092009, it sould come like 09.2009
    Thank you.
    Best Regards,
    Sasidhar Reddy Matli.

    Kindly Try this code for Month and year as input and having standard F4 help..
    INCLUDE RMCS0F0M.
    TYPES : BEGIN OF TY_SELECT,
              MONTH TYPE FTI_MONTH_YEAR,
            END OF TY_SELECT.
    DATA : WA_SELECT TYPE TY_SELECT.
    SELECTION-SCREEN : BEGIN OF BLOCK SANDEEP WITH FRAME.
      SELECT-OPTIONS : S_MONTH FOR WA_SELECT-MONTH OBLIGATORY NO INTERVALS NO-EXTENSION.
    SELECTION-SCREEN : END OF BLOCK SANDEEP.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_MONTH-LOW.
      PERFORM MONAT_F4.
    SANDEEP JAIN

  • SELECTION SCREEN FIELD FOR MONTH AND YEAR

    Hi All.
    We are developing a 'Monthly Sales Tax(payable) Report.
    they want the report based on the date(in the selection screen it will come only month and year only.).Depends on that month and year for that select-options ,it will pick up the record.
    like if, jan 2005  to march 2006.
    then it will  pick up from 01.01 .20005 to 31.03.2006  records.
    Can any body help me to resolve this.
    Thanks in advance,
    Regards,
    Venkat

    Hi Venkat,
    Copy the following code.
    DATA :  ws_billfrom    TYPE dats,
            ws_billto      TYPE dats.
    DATA : mon TYPE fcltx.
    SELECT-OPTIONS: s_month FOR mon
                MATCHCODE OBJECT zsdhtch_sh_mnth
                OBLIGATORY. "o get values for F4
    PARAMETER :  p_year LIKE bkpf-gjahr
                 MATCHCODE OBJECT zsdhtch_sh_year
                 OBLIGATORY.
    RANGES : s_date FOR sy-datum.
    DATA : ws_fcmnr TYPE fcmnr.
    START-OF-SELECTION.
      SELECT SINGLE mnr
             INTO ws_fcmnr
             FROM t247
             WHERE ltx = s_month-low.
      CONCATENATE p_year ws_fcmnr '01' INTO ws_billfrom.
      CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
           EXPORTING
                iv_date             = ws_billfrom
           IMPORTING
                ev_month_begin_date = ws_billfrom
                ev_month_end_date   = ws_billto.
      s_date-low = ws_billfrom.
      s_date-high = ws_billto.
      s_date-sign = 'I'.
      s_date-option = 'BT'.
      IF NOT s_month-high IS INITIAL.
        SELECT SINGLE mnr
               INTO ws_fcmnr
               FROM t247
               WHERE ltx = s_month-high.
        CONCATENATE p_year ws_fcmnr '01' INTO ws_billfrom.
        CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
             EXPORTING
                  day_in            = ws_billfrom
             IMPORTING
                  last_day_of_month = ws_billto.
        s_date-high = ws_billto.
      ENDIF.
      APPEND s_date.
      WRITE s_date.
    You can write your select statement here.  
      select * from dbtable where date in s_date.
    If 'HR_JP_MONTH_BEGIN_END_DATE' is nto there in your server, you can use 'RP_LAST_DAY_OF_MONTHS' in both cases.
    Regards,
    Susmitha.
    Dont forget to reward points for  useful answers

  • How to set filter criteria for month and year using in timestamp input field?

    Hi,
    I am using jdev 11.1.2.3,
    I have one problem with Report generation,,,,,,I have one report table which is in the form of VO(query based) and i want to search this table as month and year basis
    but in this table(query) that field having timestamp based value.. how to search with month name and year only.. Here i am using totally query base VO's for generating
    reports........ Can any one guide me.
    Thank You.

    You can use a inputdate, which allows you to selecte a moth, year and a day. Once the selection is made you convert it to only allow moth and date like
            <af:inputDate label="Label 1" id="id1" autoSubmit="true" value="#{bindings.myMonthYear1.inputValue}">
              <f:convertDateTime pattern="MM/yyyy"/> 
            </af:inputDate>
            <af:outputText value="Selected #{bindings.myMonthYear1.inputValue}" id="ot1" partialTriggers="id1"/>
    then you have a string holding month and year only. This value you split into two variables you or pass it as a whole parameter to the query and split it there.
    Another way is to add two static lovs one for month and one for year and use them to get to the filter values.
    Timo

Maybe you are looking for

  • Two Color Pdf Output Problem

    I'm new with InDesign coming from a Quark background. I created a 28 page booklet with CMYK cover and two color interior (black & PMS spot color) I'm working in CS4 and my print vendor is CS3. I have provided him with both the InDesign file saved dow

  • DVRCast Cache/Recorded Streams Location

    Where does FMIS 3.5.2 store recorded streams? I am running FMIS 3.5.2, FMLE 3 ("Record"), and DVRCast 1.1. I have tried numerous settings, e.g., setting <StreamManager><StorageDir> and setting LIVE_DIR in fms.ini, at the application, vhost, and serve

  • Webutil demo error ORA-06508

    hi i have installed DevSuit10g(rel2) i downloanded demo for webutil i have configured every thing as described in the example but after run when i click the button GET CLIENT INFO i get the following error message. FRM-40375: WHEN-BUTTON-PRESSED trig

  • HTTP TO XI

    hi i am trying to send an xml file from a legacy system through http to XI. can anyone please help on this any pdf or blogs regarding this will be helpful...

  • TX2500 WIndows 7 wacom pen drivers aren't compatible with single touch

    Hello I've got a TX2517au that I recently upgraded to Windows 7. Using the default drivers from wacom (3.0.0.0) I get touch and pen input working for most applications. Unfortunately this driver provides very limited pen calibration and a lack of pre