FIll in missing months

I am querying a table that includes the rider id, the date of the ride and the distance. Problem is that they may not have ridden I In a given month, so I want to include that month with a distance of 0, so all twelve months are listed. Here s my attempt...
however it doesn't pick up the zero moths.
alter PROCEDURE dbo.UM_getmonthlymiles
-- Add the parameters for the stored procedure here
@YEAR INT
, @RIDER INT
AS
BEGIN
declare @months table
monthnum int
--, mnthname varchar(3)
insert into @months
select MonthInt
from (
select 1 as MonthInt union all select 2 union all select 3 union all select 4 union all
select 5 as MonthInt union all select 6 union all select 7 union all select 8 union all
select 9 as MonthInt union all select 10 union all select 11 union all select 12
)M
select* from @months
declare @mnthmiles table
distance float
, riderid int
--, mnthname varchar(10)
, monthnumber int
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
insert into @mnthmiles
select isnull(sum(distancemiles),0), @RIDER, isnull(DATEPART(mm,ridedate), M.monthnum)--) --as [num}
from mileagelog
LEFT JOIN @months M
ON M.monthnum = DATEPART(mm,ridedate)
where DATEPART(yyyy,ridedate) = @year
and riderid = @rider
group by DATEPART(mm,ridedate), riderid, DATENAME(mm,ridedate), DATEPART(mm,ridedate), M.monthnum order by DATEPART(mm,ridedate), M.monthnum
select * from @mnthmiles

Naomi,
Thanks a lot for pinting that out :) Posting below the corrected code..
Dave, the below code runs fine for your requirement and sums up values in case there are multiple distance values present for the same rider in a month..
declare @months table
monthnum int
--, mnthname varchar(3)
insert into @months
select MonthInt
from (
select 1 as MonthInt union all select 2 union all select 3 union all select 4 union all
select 5 as MonthInt union all select 6 union all select 7 union all select 8 union all
select 9 as MonthInt union all select 10 union all select 11 union all select 12
)M
declare @rider table(id int, rdt datetime, distance int);
insert into @rider values (1, dateadd(m,-5,Getdate()),200)
insert into @rider values (1, dateadd(m,-4,Getdate()),500)
insert into @rider values (1, dateadd(m,-4,Getdate()),111) --multiple values per month for same rider
insert into @rider values (1, dateadd(m,-2,Getdate()),100)
insert into @rider values (1, dateadd(m,-1,Getdate()),1000)
insert into @rider values (1, dateadd(m,0,Getdate()),100)
insert into @rider values (1, dateadd(m,2,Getdate()),550)
insert into @rider values (1, dateadd(m,4,Getdate()),560)
insert into @rider values (2, dateadd(m,4,Getdate()),560)
insert into @rider values (2, dateadd(m,4,Getdate()),222) --multiple values per month for same rider
;with cte
as
select distinct id as riderid, m.monthnum
from @rider r cross join @months m
select c.riderid,c.monthnum,isnull(sum(r.distance),0) as distance
from cte c
left join @rider r on c.riderid=r.id and c.monthnum=month(r.rdt)
group by c.riderid,c.monthnum
order by c.riderid,c.monthnum
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

Similar Messages

  • Itunes won't fill in missing information automatically

    Hi
    Until now, my itunes always filled in missing information automatically, as i type in the first letters of the genre, the album or the artist... Now it suddenly stopped. It still works when i go on "go info", as when i select several songs i want to edit genre of, but when i do it directly on the playlist it won't work anymore.
    Does anyone have the same problem? and does someone know what to do about it/how to change it back?
    I didn't change any settings, and i already checked in preferences but nothing like autofill (un-)checking.
    All i know is that it started a few days ago, i guess when i updated my itunes. well it updated kinda automatically i just clicked yes. But i mean i didn't do anything wrong, this thing is updating every two months!
    This not-filling-in thing is really annoying because well, guess i don't need to explain why...
    So when you know how to change it back please tell me!!
    Thanks for any help!!

    It sounds like you need to restore your ipod using the latest ipod software. Once you restore the ipod sync it back with itunes and it will allow you to set it up again. Use article 60983(click on support and enter that number in the search menu) when restoring the ipod, it will guide you through the process.

  • ITunes cannot run because some of its required filles are missing

    When I started iTunes I get an error message that says "iTunes cannot run because some of its required filles are missing. Please reinstall iTunes" I have uninstalled and reinstalled but still getting the same error message. It states that itune helper was not installed properly please uninstall and reinstall. Now I have no itunes...
    I have windows vista.

    Hello Melly89,
    Thank you for using Apple Support Communities!
    It sounds like we need to uninstall not just iTunes, but its associated softwares as well.
    I recommend this article to help with accomplishing this task:
    Removing and reinstalling iTunes and other software components for Windows Vista, Windows 7, or Windows 8
    http://support.apple.com/kb/HT1923
    Regards,
    Sterling

  • How do I fill in missing album artwork?

    How do I fill in missing album artwork for my music library?

    A smart playlist with the rule Has artwork is false will help you focus on the tracks that need artwork.
    Option-(or right)-click > Get Album Artwork should get artwork from the store if the album can be recognised. Otherwise Google is your friend, search for the relevant album, copy the image & paste it in to iTunes.
    Note sure if affects Mac users but there is a copy/paste bug with the current build (10.4.0.80) which can result in a blank image being pasted. Saving the image locally to your computer, and then dragging in the saved image will work around that.
    tt2

  • Windows 7 fills in missing glyphs - suggestions?

    Hi all,
    I wasn't sure how to title the thread in a way that caught what I was trying to get at, so please bear with me.  And I do realise that what I'm asking about is a Windows issue rather than an Adobe one, but I thought people here might have an insight into the problem, given that it affects those who focus on and use fonts specifically.  I haven't been able to find help or much engagement on any Windows forums, where the discussion is more about operating system capabilities and the issues of fonts are somewhat arcane to most posters.
    So please indulge me for a moment, and if you can help me, then thanks!
    I'm new to Windows 7.  What I've discovered is that Windows 7 has substantially changed the way it handles and displays fonts.  (Vista may have as well, but I never stepped into that pond.)  In both the Font Viewer and in any Font Manager that I've tried, Windows 7 fills in any missing glyphs in a font within the basic ASCII character set with an auto-generated generic set of glyphs, often making it very hard - or at least time- and effort-intensive - to determine which glyphs are from the font and which glyphs are auto-filled.  It was meant to be helpful, I imagine, but it's really not.
    In fact, I find it really, *really* frustrating, because it makes it so hard to glance at the display of the font and see quickly whether it's got the glyphs I'm looking for or not.  (Some fonts are incomplete, for various reasons.  Sometimes they use the basic 1252 encoding but not the standard glyphs, and they too get any missing glyphs autogenerated.)
    Am I the only one this bothers?
    More to the point:  Has anyone found a way to turn this "feature" off?  Or can anyone give me an insight on the issue that I may not have thought about, especially ways to use it productively?  I find it really counter-intuitive and enormously unhelpful and distracting.
    But enough whingeing.  Any help or thoughts would be greatly appreciated.

    Miguel.
    Thanks for the information.
    Why was this done, do you know?  I can't think of a circumstance where this would actually be helpful, especially since, as you say, there is apparently no mechanism for the user to have control over the face that's used to fill empty glyphs.  For anyone purposely using fonts, it would seem to be more of an intrusion than assistance.  Nobody using fonts as part of purposeful design will want glyphs from a different face inserted out of their control;  you either use the font as is, or do something about the incomplete character set (if you have that capability), or you choose a different font.
    But maybe I'm missing something?  What am I not understanding?
    And why does it not happen with every font, just the overwhelming majority?  I haven't been able to spot a pattern to those where this "fallback" doesn't kick in, but in some instances it doesn't.  The Font Viewer fills any missing glyphs with the .notdef character;  in others, it inserts its own characters, and ignores the .notef character.  I can't figure out why.
    By the way, John, as I said every font manager I've tried just shows what Font Viewer does, which is why I was sure it was an OS issue.  And Dov, yes I realise the problem itself has to go back to Microsoft, as I tried to make clear, but already I've got more information on the issue from posting here than the questions I've asked in Microsoft and Windows forums, where most people know nothing about fonts or their use.

  • How to get count for missing month

    I created a view as follows:
    CREATE OR REPLACE FORCE VIEW "Vinfection1" ("MONTH", "COUNT") AS
    select "MONTH","COUNT" from (
    select to_char(s.pdate,'Mon-yyyy') as month, count(*) as count
    from surproc s, diagnosis_surproc d
    where s.surprocid = d.surprocid and d.diagnosisid in ('506', '507', '508', '509', '510')
    group by to_char(pdate,'Mon-yyyy'))
    order by to_date(month,'Mon-yyyy')
    Some months are missing in the view. I want to put that month and 0 in the view. How to do it?
    Thanks,
    Jennifer

    Hi, Jennifer,
    You need to outer-join to some table or result set (such as all_months, below) that has one roe per month.
    Here's one way:
    CREATE OR REPLACE FORCE VIEW Vinfection1 (month, month_s, cnt) AS
    WITH    all_months     AS
         SELECT  ADD_MONTHS (first_month, LEVEL - 1)     AS month
         FROM     (
                  SELECT  TRUNC (MIN (pdate), 'MONTH')     AS first_month
                  ,         TRUNC (MAX (pdate), 'MONTH')     AS last_month
                  FROM    surproc
         CONNECT BY     LEVEL <= 1 + MONTHS_NETWEEN (last_month, first_month)
    SELECT  a.month
    ,     TO_CHAR (a.month, 'Mon-yyyy')     AS month_s
    ,     COUNT (*)                 AS cnt
    FROM              all_months      a
    LEFT OUTER JOIN      (     surproc               s
                   JOIN   diagnosis_surproc      d  ON   s.surprocid     = d.surprocid
                                          AND  d.diagnosisid     IN ('506', '507', '508', '509', '510')
               )     ON  a.month     = TRUNC (s.pdate)
    GROUP BY  a.month
    /Avoid table- and column names that are non-standatrd (such as names that need double-quotes), or are built-in function names (such as COUNT).
    Don't use ORDER BY in a view. Almost anything you do with the view will cause the ordering to be lost anyway.
    Even if you do have an ORDER BY clause in the view, you'll often want to ORDER BY month. Rather than call TO_DATE whenever you need to sort, I suggest having two month columns; month (whcih is a DATE) for sorting, filtering and joining, and month_s (whcih is a VARCHAR2) for displaying.
    Use ANSI join syntax, especiallly for outer joins.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    Edited by: Frank Kulash on Mar 20, 2012 12:03 PM
    Added outer join condition

  • Iphoto crashed before filling in all months of a calendar for printing

    Now I am unable to complete the calendar from my photo file as before. Is there any way to complete the current calendar?

    Now I am unable to complete the calendar from my photo file as before. Is there any way to complete the current calendar?

  • Fill in missing song ID info?

    Hi all-
    Back before the days of iTunes, I used some random app to rip my entire CD collection into my computer. This did not download CDDB information to the computer, I actually entered song name, number and artist manually.
    I'm looking for a way to take my entire collection and update the ID3 tags so that I have a complete set of info (year, album and genre would be most helpful!) for all of my music, without doing to each song (or groups of songs) manually.
    Anyone have any ideas? Thanks for the help.

    There is probably no app out there to do that. For a program to be able to do that an application would have to what song each file actually was to be able to get the Meta data for it.
    Since there are lots of different music file types. And each type can be made differently with options like sampling freq, and bit rate, etc. there is not a good way to make that match.
    Each copy of a CD on the other hand is exactly the same bit for bit so a figure print can be created for each CD

  • Missing calendar month

    Hi experts,
    What is the cause if there is a missing calendar month in my query e.g.
    Month Value
    1         123
    2         123
    3         123
    4         123
    5         123
    6         123
    8
    9
    10
    11
    12
    As you can see, I cant see the month of July. Initially I thought it is because the data havent been loaded into BW yet, but then August-December data are also havent been loaded into BW but they still appear in my report.
    How can I insert the missing month ie July into the report?
    Appreciate your help.
    Points will be rewarded.

    Hi AHP,
    I cant help but to express my utmost admiration on your knowledge in BW
    You're right, I have access to the query now and I found out that Aug-Dec have some values in other columns. That why it appears in the query.
    After changing the Display Zero (from previously Suppress Zero), July row still wont appears. I suspect there is no data for that particular month. However, as I dont have access to RSA1, LISTCUBE, and RSRV, I can only imagine that is being the case.
    Now, the user wanted to add July row to the query, (assuming) even though there is no data available for that month. How can this be accomplished? My understanding is that, we can only do this if we add a new line in SAP R/3 (Month = July) with zero value and extract that line into SAP BW.

  • Multiplot graph with missing values fills them with zero instead of NaN

    I have a waveform graph with multiple arrays (2D) which has different numbers of points in each array.  LabVIEW finds the array with the most points and then plots all arrays with that many points.  It assigns the missing points a value of zero and displays those zero values.  This means arrays with fewer points than the maximum will have values of zero appear in their plots.  This can be avoided by filling in missing points with NaN.  I am acquiring data in a loop and displaying it which requires continuous determination of the number of actual points and filling in of missing points with NaN.  Not difficult, but this could be avoided if LabVIEW would fill missing points with NaN instead of with zero.  Any way to have this happen automatically ?
    Steve
    Attachments:
    Graph MultiPlot Missing Data.vi ‏18 KB

    You can also consider using an XY graph so you don't have to do additional data manipulation. See attached for comparison.
    Attachments:
    Graph MultiPlot Missing Data mod.vi ‏22 KB

  • SQL Loader XML Missing Data

    I am trying to load a XML file via SQL Loader. My loader file is as follows:
    LOAD DATA
    INFILE 'C:\Infile.xml' "str'</Record>'"
    BADFILE 'C:\Infile.bad'
    Replace
    INTO TABLE Cust_Table
    TRAILING NULLCOLS
    dummy filler terminated by ">",
    Month enclosed by "<Mo>" and "</M0>"
    LOC_ID enclosed by "<LOC_ID>" and "</LOC_ID>",
    LOC_DESC enclosed by "<LOC_DESC>"and "</LOC_DESC>",
    Cust_ID enclosed by "<Cust_ID>" and "</Cust_ID>",
    Cust_Name enclosed by "<Cust_Name>" and "</Cust_Name>" )
    The problem I'm having is for some records the Cust_Id and Cust_Name is missing in the file. The error I'm getting when trying to load the file for those records is:
    Rejected - Error on table Cust_Table, column Cust_Id.
    Initial enclosure character not found
    Not sure what I need to add to the loader file to resolve this error.
    TIA,
    Todd

    I would suggest u use External tables since its more flexible then
    sqlloader & is a better option.
    For using external tables
    1)u will have to create a directory first
    2)Generally creation od directory is done by sys,hence after creating the directory
    privileges read & write to be provided to user .
    3)Creation of external tables.
    4) Now use the table as a normal table to insert ,update delete in
    ur table.
    U can get more information from
    http://www.oracle-base.com/articles/9i/SQLNewFeatures9i.php#ExternalTables
    Create Directory <directory_name> as <Directory path where file be present>
    Grant read,write on directory <directory_name> to <username>
    CREATE TABLE <table_name>
    (<column names>)
    ORGANIZATION EXTERNAL
    TYPE ORACLE_LOADER
    DEFAULT DIRECTORY ,directory_name>
    ACCESS PARAMETERS
    RECORDS DELIMITED BY NEWLINE
    FIELDS TERMINATED BY ','
    LOCATION (<filename>)
    PARALLEL 5
    REJECT LIMIT 200;
    Hope this helps.

  • Help to fill BPS Cube with same data in a Cube with these conditions

    Hi,
    I need some help in implementing BPS in a small project. (Integrated Planning is not available).
    An existing cube, Cube1 has: Year/month, Year, char1, char2, keyfig1, keyfig2
    Keyfig1 is filled directly from R3 with actuals; keyfig2 (planned values) is  filled manually filled with a monthly flat file load.
    Now, there is a change in direction to fill keyfig2 through BPS features and bring in additional key figures all based on keyfig1.
    Cube2 has been created only for the purpose of this BPS project. Cube2 was a copy of Cube1(with no data). For Cube1, I have created a Planningarea1 and PlanningLevel1; and for Cube2, Planningarea2 and PlanningLevel2 in BPS0.
    How do I fill the BPS Cube2 with the same data as in BPS Cube1 with the following conditions:
    keyfig1 : same as source value from R3 (not modifiable)
    keyfig2 : modifiable by users only on the first and second of the month.
    keyfig3 : keyfig1 * 1.1
    keyfig4 : keyfig1 of previous Year/month 
    keyfig5 : same as source value from R3 (But modifiable)
    keyfig6 : same as keyfig5 as of last day of 20th of the current month (not modifiable)
    The goal is to create a multi planning area to join the two cubes. Hints all that will also be appreciated.
    Thanks

    Your thought of having a multi area is right.
    Create a multi area and being the basic areas to which you have assigned cube 1 and cube 2 underneath the multi area.
    UNder your planing package, create a function of type Formula and create a parameter set like this:
    = * 1.1.
    Just this one line will is enough.
    TO get keyfig 4 as previous month's key fig; you need another fox. To do this, you need to have a BPS variable to et previous month and use this variable in the parameter set.
    Your fox will be like this.
    DATA CURRMONTN TYPE 0CALMONTH.
    DATA PREMONTH TYPE 0CALMONTH.
    {KEYFIG4, CURRMONTH} = {KEYFIG1, PREMONTH}.
    To make users modify only on days 1 and 2, you need to define a dara slice.
    Ravi Thothadri

  • Display month in the column

    hello...i have a report that actually need a layout of displaying the month in the column. the format as below:
    last month new loan (09.2008), this month new loan (10.2008), the month here will change based on the user input of the current month and the report will auto display out the month as above. is there any way that we can do this??? do i need to create another variable for this?

    Hello,
    you have to create a new variable for e.g. 0calmonth. This variable can be used in your keyfigures.
    The variable can be filled with actual month. To get the last month data you can use the OFFSET function (-1 last month) in Query Designer.
    Regards,
    Markus

  • UIX 2.1.21: Date OnBlurValidator automatically add current month or year?

    Would be nice if the OnBlurValidator for a UIX Date field could automatically add a missing month or year.
    e.g. Format dd.mm.yyyy
    When the user enters 01.01. the current year could be added automatically.
    Or when the users only enters 01. the current month and year could be added.
    Would be a nice feature additionally to the already existing lenient-date-formats = true.
    Really great would be to allow entering values like "now" / ".", "yesterday" / "-" or "tomorrow" / "+" that are evaluated to the according dates (of course internationalized).
    Thanks, Markus

    hey mill1640,
    Did you ever get your iPhone to register with iTunes? I just upgraded as well to Snow Leopard, and my my isn't recognized at all also.
    If you did get this resolved, I would appreciate a little suggestion in the right direction.
    Many thanks,
    Josh

  • Data missing from W_GL_BALANCE_F table

    Hi:
    OBIA: 7.6.3
    Source: EBS 11.5.10
    I have run and re-run a full load for Financial Analytics, and, strangely, data is missing for a few months. When I have re-run, I selected Reset Data Sources in DAC. Specifically, data is missing in W_GL_BALANCE_F for Dec 2010 and Feb-May 2011. All other months that could contain data, do contain it. I have verified that transactions exist in GL_BALANCES table for the missing months.
    Can anyone suggest what might cause this behavior?
    Thank you.

    I assume they also do not exist in the W_GL_OTHER_FS staging table. Can you check this table as well as the TMP table that precedes it. The issue seems to be on the Extract side (not the GL Balance Load side). Each source system may have specific preceding tables for the GL Journal Lines. Also, are you extracting from the GL_BALANCES in EBS or are you calculating the balances in the ETLs? There are 2 options to configure here..check the configuration guide. I would just work backwards from W_GL_OTHER_FS and see why these are not coming through. If this was helpful, please mark as helpful or correct.

Maybe you are looking for

  • Merge statement

    i would like to know if it is possible to identify the row that is causing the problem when you use a merge statement in pl/sql. i know if you create a cursor and then loop through the data you can identify the column but what about if i have only a

  • Is there any way to get facetime on a toshiba with windows 8?

    i have a toshiba laptop with windows 8 installed and im trying to communicate with my friend who has a 4th generation ipod touch. he has facetime and i am trying to find out if i can get it on my laptop so i can contact him. is there any possible way

  • Converting to spot colors in InDesign

    Hi, Im trying to create a two color job in InDesign that will be black and red. The problem I have is that our imagesetter is not separating the colors. I was told that the red color needs to be a spot color in InDesign for the imagesetter to know to

  • Maximum Allowable Paramters in Report

    Post Author: dthorpe CA Forum: Crystal Reports I have an existing report that uses several text parameters that contain comma delimited lists.  The stored procedure takes the comma delimited lists, put them in a temp table and uses that as part of it

  • 3Gs not playing movies properly -  help !

    I have recently tried playing movies on my new iphone 3gs and now some movies have big green blobs flashing up all over the screen,all these movies played on my last iphone without a problem. P.s. these are mp4's