Query optmization age in year

Hey there,
I calculate the year difference between two dates by doing the following thing :
TRUNC(MONTHS_BETWEEN(RES.SAMPLE_SAMPLING_DATE,RES.PATIENT_BIRTHDATE)/12)+1Do you think that I can optimized this query or do you know any other ways to do the same calculation ?
Regards,
Jarod.

I didn't find my happiness in previous topic forum, mostly, difference between two dates in hours or minutes. Have a look here: https://forums.oracle.com/forums/search.jspa?threadID=&q=age+calculate+leap+years&objID=f75&dateRange=all&userID=&numResults=15
Actually, I just want to know if you think if my query is sufficiently optimized.It is a common way to calculate age, seen it more than once. You'll have to run tests on your specific configuration to see what could be improved, but I wouldn't spend hours on that.

Similar Messages

  • To Calculate age in years

    Hi Experts,
                        I need to calculate the age in years. I have the date of birth already in my infoprovider that  iam using for my query.
    The user will be entering the date on which he want to calculate the age in the selection screen and the date will be stored in a variable..
    Now how to calculate the age in years and display it as a separate coloumn in the report?
    Regards,
    Khan

    Hi,
    Here 1st create the one formula variable on birth date
    then create one more formul variable customer exit varaible with user entry here u cna use the i_step = 2 there user enters which ever that date based on that date it executes
    in CKF: this  customer exit user entry varible - birth date formula varible
    whenever the user enters date based on that now u r getting  days of the employe AGe
    now that CKF can be used in another CKF  by using age/365
    now in report u can keep only second CKF.
    Thanks & Regards,
    Sathish

  • Need age in years based on his/her next birth day.

    Hi,
    I need to Print age in years based on his/her next birth day.
    SELECT TO_CHAR(TRUNC(MONTHS_BETWEEN((SYSDATE ), P.birth_date)/12)) A from employee I used the above code but I get the age with reference to the sysdate only. But what I require is the age based on next birthday.
    For ex: Birth day: 24FEB2000
    Then my expected output is 10.
    If my birthday would have been 24DEC2000, then I would expect a result of '9', please help me with a function or a simple sql statement to code this.
    Thank You

    Maybe something like:
    SQL> SELECT sysdate FROM Dual
      2  /
    SYSDATE
    17-JUN-09
    1 row selected.
    SQL> WITH test_tab AS
      2       (SELECT TO_DATE ('24FEB2000', 'DDMONYYYY') birth_date
      3          FROM DUAL
      4        UNION ALL
      5        SELECT TO_DATE ('24JUL2000', 'DDMONYYYY') birth_date
      6          FROM DUAL
      7        UNION ALL
      8        SELECT TO_DATE ('17JUN2000', 'DDMONYYYY') birth_date
      9          FROM DUAL)
    10  SELECT birth_date,
    11         CASE
    12            WHEN SIGN (  TO_DATE (   TO_CHAR (birth_date, 'DDMON')
    13                                  || TO_CHAR (SYSDATE, 'YYYY'),
    14                                  'DDMONYYYY'
    15                                 )
    16                       - TRUNC (SYSDATE)
    17                      ) <> 0
    18               THEN TRUNC (MONTHS_BETWEEN (TRUNC (SYSDATE), birth_date) / 12)
    19                    + 1
    20            ELSE TRUNC (MONTHS_BETWEEN ((SYSDATE), birth_date) / 12)
    21         END age
    22    FROM test_tab
    23  /
    BIRTH_DAT        AGE
    24-FEB-00         10
    24-JUL-00          9
    17-JUN-00          9
    3 rows selected.
    SQL> Hmm... Sean's Query is better....
    Regards,
    Jo

  • Sql query with dynamic fiscal year

    Hi,
    I wrote this query with static fiscal year and fiscal period, I need info on making the variables dynamic
    Fiscal year : starts from July1st. So this year until June'30 it is '2011' and from July'1st its '2012'
    Fiscal period: July1st its '1' and June'1st its '12'
    Query:
    select distinct o.c_num, o.ac_num, s.sub_ac_num, o.fiscal_year, o.ac_exp_date, s.sub_ac_ind
                             from org_account o
                                  left outer join sub_account s
                                  on o.c_num = s.c_num and o.ac_num = s.ac_num
                             where (o.ac_exp_date >= CURRENT_DATE or o.ac_exp_date is null)
                             and o.fiscal_year = *'2011'* --> need to be dynamic
                             and o.fiscal_period = *'12'* --> need to be dynamic
    thanks,
    Mano
    Edited by: user9332645 on Jun 2, 2011 6:55 PM

    Hi, Mano,
    Welcome to the forum!
    Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data.
    Always say which version of Oracle you're using.
    Since this is your first thread, I'll post some sample data for you:
    CREATE TABLE     table_x
    (     dt     DATE
    INSERT INTO table_x (dt) VALUES (DATE '2010-12-31');
    INSERT INTO table_x (dt) VALUES (DATE '2011-01-01');
    INSERT INTO table_x (dt) VALUES (DATE '2011-06-02');
    INSERT INTO table_x (dt) VALUES (DATE '2011-06-30');
    INSERT INTO table_x (dt) VALUES (DATE '2011-07-01');Is this the output you would want from that data?
    DT          FISCAL_YEAR     FISCAL_PERIOD
    31-Dec-2010 2011            06
    01-Jan-2011 2011            07
    02-Jun-2011 2011            12
    30-Jun-2011 2011            12
    01-Jul-2011 2012            01If so, here's one way to get it:
    SELECT       dt
    ,       TO_CHAR ( ADD_MONTHS (dt, 6)
                , 'YYYY'
                )     AS fiscal_year
    ,       TO_CHAR ( ADD_MONTHS (dt, 6)
                , 'MM'
                )     AS fiscal_period
    FROM       table_x
    ORDER BY  dt
    ;Since your fiscal year starts 6 months before the calendar year, you need to add 6 months to the actual date to get the fiscal year and month.
    The query above produces strings for fiscal_year and fiscal_period. If you'd rather have NUMBERs, then use EXTRACT instead of TO_CHAR:
    SELECT       dt
    ,       EXTRACT (      YEAR
                FROM     ADD_MONTHS (dt, 6)
                )     AS fiscal_year
    ,       EXTRACT (      MONTH
                FROM     ADD_MONTHS (dt, 6)
                )     AS fiscal_period
    FROM       table_x
    ORDER BY  dt
    ;The first query will work in Oracle 6 (and higher).
    I'm not sure when EXTRACT was introduced. It definitely works in Oracle 10, and may be available in earlier versions, too.

  • Cannot find  the age in years csv file  in  the application server

    Hi,
      I want to upload the age in years hierarchy from the CSV  file AGE_E.CSV that should be available in the application server.
      When i try to preview file in the info package, a message is thrown which says that the file does not exist, which means that the perticular file is not present in the application server.
      Can any one of you please tell me where else can i find this file.
    Regards,
    Chetana.

    dear Chetana,
    transaction AL11 can be used to check the file location.
    check DIR_TEMP or DIR_TRANS. or ask basis where the file is put.
    hope this helps.

  • Any query to get 10 years data from tables of hundreds of schemas?

    Hi,
    Is there any query to extract 10 years of data from schema ( may be 100 in number) and then export that data to some other database.
    THanks

    982955 wrote:
    Hi,
    Is there any query to extract 10 years of data from schema ( may be 100 in number) and then export that data to some other database.
    THanksYES, it depends
    How do I ask a question on the forums?
    SQL and PL/SQL FAQ

  • SQL date query problem with century/ year

    We have an oracle database with about 6 million records. There is a date field called Entered Date that ranges from 1985 to the present.
    The majority of these records were entered prior to Jan 1 2000.
    If I run a query like
    select count(*) from (tablename) where entered_date < '01-JAN-00' I get 0
    if I do
    select count(*) from (tablename) where entered_date < '31-DEC-99' I get 0
    BUT IF I DO
    select count(*) from (tablename) where entered_date < '01-JAN-00' I get 6 million records
    or
    select count(*) from TREASURY.ctrc where entrydate > '31-DEC-99' I get 6 million records
    I've tried the same queries using 4 digit years but get the same results; it thinks that 2000 is the less than 1999
    How do I get around this?
    thanks

    Hi,
    975204 wrote:
    there are 6 million records on the table
    about two thirds have a date prior to Jan 1 , 2000How do you know that? From knowledge of the application, you may know that two thirds of them are supposed to have dates prior to 2000, but if
    SELECT  COUNT (*)
    FROM      TABLE_NAME
    WHERE      ENTRYDATE < TO_DATE ( '01-JAN-2000'
                           , 'DD-MON-YYYY'
    ;returns 0, that's pretty strong proof that none of them actually do.
    When I look at the dates , they display as 31-DEC-86Another example of why using 2-digit years is such a bad idea.
    I cant actually provide dump of this clients confidential dataSeriously; you can't provide one DUMP output? You've already said that it displays as 31-DEC-86, so even if the fact that 1 entry in the 6-million row table was done on December 31, 1986 was such a big secret, it's already out, and you won't be causing any more harm by showing the DUMP results.
    I ran the query with the same format as the date ie
    SELECT COUNT(*) FROM TREASURY.CTRC WHERE ENTRYDATE < TO_DATE ( '31-DEC-99'
    , 'DD-MON-YY'
    but same results
    if the column is defined as a DATE type, does Oracle make a distinction based on how the data displays, meaning does it think that 31-DEC-86 is different than 31-DEC-1986?No, all DATE columns have the same format. A DATE may be displayed one way of the other, but it is stored as neither.
    Do I need to convert all the data to a 4 digit year? You should always display dates with a 4-digit year.
    Run an update query that says if year >= 80 and <= 99 add 19 in front of the year, else add 20 in front of the yearLet's find out exactly what the problem is, first.
    Did you see Ascheffer's message? ^1^ It was dated just a couple of minutes before your last message, so you might not have noticed it. Run it to see what the actual 4-digit years are.
    If it shows, for example, that there are a lot of entrydates in the years 2080 to 2099, and you decide that all of those really should be 100 years earlier, then use ADD_MONTHS to correct them:
    UPDATE     table_name
    SET     entrydate = ADD_MONTHS ( entrydate
                               , -100 * 12
    WHERE   entrydate >= TO_DATE ( '01-JAN-2080'
                             , 'DD-MON-YYYY'
    AND     entrydate <  TO_DATE ( '01-JAN-2100'
                             , 'DD-MON-YYYY'
    ;Edited by: Frank Kulash on Mar 15, 2013 6:09 PM
    ^1^ Obviously, you did see Ascheffer's message; I was still typing the message above when you posted another one.

  • Age in years and length of service wrongly calculated

    I have BI 7.0 implemented by SAP itself , they installed only the business content without any customization
    in HR For The Cube HeadCount 0PAPA_C02  the key figure Age in Years 0AGE_NC is calculating in a wrong way it is subtracting from 1999
    and the field length of service in years 0SRVCLEN_NC is subtracting from 1999 for dates less than 1999 and from 2199 for date more than 1999
    i have searched alot for this but i can't find any solution

    the problem was in the 0CALDAY , it should be set before the calculation
    so i set it to today and everything become fine

  • Sample query for Aging Report

    Hi! Anybody who has a sample sql query for aging report? basically this is the table structure and sample data
    bill_no B1-01 B1-02 B1-03
    bill_date 01-JAN 01-FEB 01-MAR
    previous_balance 100 600 800
    current_charges 500 200 400
    total_due 600 800 1200
    As of march 1, total due is 1200. how can i get the breakdown of 1200 as to the number of days it has been due. ex. 500 (60 days old 01-JAN to 01-MAR), 200 (30 days old), 400 (current)
    please help. thanks!
    null

    SELECT CEIL((SELECT MAX(Bill_Date) FROM Bill)- Bill_Date) Days , Previous_Balance, Current_Charges FROM Bill ORDER BY Days ASC
    Then create a matrix reprot.

  • Why contacts birthdays are being showed in iCloud calendar all with the same age (11 years)??

    Why contacts birthdays are being showed in iCloud calender all with the same age (11 years) ?? There is a solution to solve this problem ??
    Thank-you

    I cannot agree more with your comments! What a way to frustrate your customers!
    I have been having an issue with iCloud on Mac where it kept asking me for my password and sometimes would, sometimes would not continue to access my iCloud mail. Today it just refused to connect to iCloud mail.
    I looked in the Mail, Contacts and Calendars in my MacBook Pro settings and discovered that 2 iCloud accounts were present. One with my original Apple ID (a gmail address) and a second with my new iCloud email ( an @me.com address). Having deleted the second account, using the new @me.com address everything is working fine.
    So from my viewpoint when I moved over to iCloud I was asked to sign in with my Apple ID (the gmail address) then to create an @me.com address. However, as far as I can see all sign ins to the new @me.com account on Macbook, iPhone and iPad need to be done through the old Apple ID (the gmail address). Is that confusing and just plain crazy???
    Further, after creating the new @me.com address I soon found out that this is apparently now forever bound to my old Apple ID and cannot be changed. I mean why can't I delete the iCloud account and start anew with a different @me.com address??? Also, as everybody using iCloud must create an @me.com address why on earth can I not get rid of my old gmail address and have my entire Apple ID accessed through the new @me.com address? Creating a whole new Apple ID will not solve this as we are unable to transfer purchases between accounts.
    Apple products are great IMHO, but they do seem to not think things through in a very big way sometimes......

  • Query to pick up people of retirement age 1 year in advance

    Hi,
    I wrote the below query to pick up all staff who will be of retirement age in a year's time. This will be used in an alert that must go to payroll 1 year before retirement date, then 6 months before retirement date and then finally 1 month before retirement date.
    select distinct papf.employee_number
    , papf.full_name
    , apps.meds_hr_util_pkg.return_department(papf.person_id) org
    , papf.date_of_birth
    , (select payroll_name from pay_all_payrolls_f where payroll_id = paaf.payroll_id) payroll_name
    , (select first_name||' '||last_name from per_all_people_f where person_id = paaf.supervisor_id and trunc(sysdate) between effective_start_date and effective_end_date) mgr
    , (select email_address from per_all_people_f where person_id = paaf.supervisor_id and trunc(sysdate) between effective_start_date and effective_end_date) mgr_email
    , add_months(to_date(DECODE(to_char(papf.date_of_birth, 'DD-MON'), '29-FEB', '28-FEB', to_char(papf.date_of_birth, 'DD-MON') ) ||to_char(sysdate, '-YYYY')),-12) date_12month_advance
    , add_months(to_date(DECODE(to_char(papf.date_of_birth, 'DD-MON'), '29-FEB', '28-FEB', to_char(papf.date_of_birth, 'DD-MON') ) ||to_char(sysdate, '-YYYY')),-6) date_6month_advance
    , add_months(to_date(DECODE(to_char(papf.date_of_birth, 'DD-MON'), '29-FEB', '28-FEB', to_char(papf.date_of_birth, 'DD-MON') ) ||to_char(sysdate, '-YYYY')),-1) date_1month_advance
    , trunc(months_between(add_months(to_date(DECODE(to_char(papf.date_of_birth, 'DD-MON'), '29-FEB', '28-FEB', to_char(papf.date_of_birth, 'DD-MON') ) ||to_char(sysdate, '-YYYY')),-12),papf.date_of_birth)/12) age_12mon
    --into &emp_no, &emp_name, &org, &date_of_birth, &payroll_name, &mgr, &mgr_email, &retirement_date     
    from per_all_people_f papf
    ,per_all_assignments_f paaf
    ,per_person_type_usages_f pptuf
    ,per_person_types ppt
    where papf.person_id = paaf.person_id
    and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
    and trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date
    and paaf.primary_flag = 'Y'
    and paaf.assignment_type = 'E'
    and papf.person_id = pptuf.person_id
    and pptuf.person_type_id = ppt.person_type_id
    and trunc(sysdate) between pptuf.effective_start_date and pptuf.effective_end_date
    and ppt.system_person_type = 'EMP'
    and ppt.user_person_type != 'Pensioners'
    and trunc(months_between(add_months(to_date(DECODE(to_char(papf.date_of_birth, 'DD-MON'), '29-FEB', '28-FEB', to_char(papf.date_of_birth, 'DD-MON') )
    ||to_char(sysdate, '-YYYY')),-12),papf.date_of_birth)/12) >= 62
    and trunc(sysdate) in (add_months(to_date(DECODE(to_char(papf.date_of_birth, 'DD-MON'), '29-FEB', '28-FEB', to_char(papf.date_of_birth, 'DD-MON') ) ||to_char(sysdate, '-YYYY')),-12)
    , add_months(to_date(DECODE(to_char(papf.date_of_birth, 'DD-MON'), '29-FEB', '28-FEB', to_char(papf.date_of_birth, 'DD-MON') ) ||to_char(sysdate, '-YYYY')),-6)
    , add_months(to_date(DECODE(to_char(papf.date_of_birth, 'DD-MON'), '29-FEB', '28-FEB', to_char(papf.date_of_birth, 'DD-MON') ) ||to_char(sysdate, '-YYYY')),-1)
    and to_char(papf.date_of_birth, 'DD-MON') != '29-FEB'
    order by 1
    The query works only when I have this line in
    " and to_char(papf.date_of_birth, 'DD-MON') != '29-FEB' "
    As soon as I remove it I get an ORA-01847: day of month must be between 1 and last day of month error. I can't seem to figure out why because there is 1 person with a birth date of 29-FEB and I am catering for this in the query. Also, I am using TO_DATE for the values so using add_months and months_between should not be an issue.
    Please help....maybe someone else can see something I am missing...
    Thanks
    Shalantha

    Hi,
    To find people who are 65 years old (or older) as of today, you can simply say
    WHERE     date_of_birth <= ADD_MONTHS ( SYSDATE
                                       , -12 * 65
                                )ADD_MONTHS knows how to adjust for leap years, but it may not adjust for them the way you expect.
    If today is February 28, 2013, the condition above will include people born on Februry 29, 1948. That's actually 1 day before they reach 65. If that's a problem, the solution is slightly more complicated.
    If today is March 1, 2013, it will include people born on Februry 29, 1948.
    If today is February 29, 2012 (or February 28, 2012) it will include people born on February 28, 1947, but not people born on March 1, 1947.
    To find people who will be 65 years old (or over) 3 months from today:
    WHERE     date_of_birth <= ADD_MONTHS ( SYSDATE
                                       , (-12 * 65) + 3
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data. Simplify the problem as much as possible.
    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 May 26, 2011 11:48 AM

  • Can using query create aging report for GL Account

    Hi all expert,
    I have a challenge scenario which customer request print out aging report for the following GL Account.
    This is not a business partner account. However, customer want display like aging report.
    30 days aging report for the following GL accounts by projects:-
         i)     WIP (Work In Progress) account
         ii)     Accrued Revenue account
         iii)     Accrued Cost account
    Examples:
                            Current Balance       30 day   60 day  90 day   120 day
    Account  WIP         10000               2000        3000      5000     0
    Any idea or example given? If yes, can you provide a query here?
    Regards,
    Eric Tan

    Hi Eric
    In standard SAP Business One this is difficult as the reports are 2 dimensional. To achieve this you will need to write multiple select statements into a temporary table and then select the final result from the temp table. Here is a sample for you to test:
    USE [*DATABASE_NAME*]
    GO
    /****** Object:  StoredProcedure [dbo].[REPORT_NAME]    Script Date: 04/24/2009 13:17:21 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE proc [dbo].[*REPORT_NAME*]
    as
    set nocount on
    begin
    DECLARE @Day_no varchar(2)
    DECLARE @Month_no varchar(2)
    DECLARE @Year_no varchar(4)
    DECLARE @Start_Date Datetime
    SET @Day_no = DAY(GetDate())
    SET @Month_no = MONTH(GetDate())
    SET @Year_no = YEAR(GetDate())
    SET @Start_Date = @Year_No + '/' + @Month_no + '/' + @Day_no --  + '/' + @Year_No
    IF OBJECT_ID(N'tempdb..#CRDAGEING', N'U') IS NOT NULL
    drop table #CRDAGEING
    SELECT T0.[CardCode] AS [CardCode], T0.[CardName] AS [CardName], -T0.[Balance] AS [Balance], CAST(0 AS MONEY) AS [Current], CAST(0 AS MONEY) AS [1Week], CAST(0 AS MONEY) AS [2Weeks], CAST(0 AS MONEY) AS [3Weeks], CAST(0 AS MONEY) AS [4Weeks], CAST(0 AS MONEY) AS [5Weeks], CAST(0 AS MONEY) AS [6Weeks], CAST(0 AS MONEY) AS [Over6Weeks], CAST(0 AS MONEY) AS [Avg3Months], CAST (0 AS MONEY) AS [Onhand] INTO #CRDAGEING FROM OCRD T0 WHERE T0.[CardType] = 'S' -- and T0.[CardCode] <> '' --and T0.[DocDate] >= @FromDate AND T0.[DocDate] <= @ToDate
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] <= @Start_Date GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] >= DATEADD(DAY,1,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,8,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,8,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,15,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,15,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,22,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,22,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,29,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,29,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,36,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,36,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,43,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,43,@Start_Date)  GROUP BY T1.[ShortName]
    SELECT SR.[CardCode], MAX(SR.[CardName]), SUM(SR.[Balance]) AS [BalanceOwing], SUM(SR.[Current]) AS [Current], SUM(SR.[1Week]) AS [1Week], SUM(SR.[2Weeks]) AS [2Weeks], SUM(SR.[3Weeks]) AS [3Weeks], SUM(SR.[4Weeks]) AS [4Weeks], SUM(SR.[5Weeks]) AS [5Weeks], SUM(SR.[6Weeks]) AS [6Weeks], SUM(SR.[Over6Weeks]) AS [Over6Weeks] FROM dbo.#CRDAGEING SR GROUP BY SR.[CardCode] ORDER BY SR.[CardCode]
    END
    Go to Microsoft SQL Studio manager and select your company database. Then expand the list and select Programmability > Stored Procedures. Right click on Stored Procedures and select New Stored Procedure. Copy the above code over the code in the edit window and change the database name as well as report name. Then select Execute to create the stored procedure. If you make changes, remember to change the word CREATE to ALTER (with other words CREATE for the first execute, and ALTER thereafter). Then in SAP Business One create a new query and leave everything blank. Click on execute and select the pencil to change to edit mode. Remove the words SELECT and type in EXEC REPORT_NAME (change the REPORT_NAME to the name you used in SQL). Then execute again and the results will be displayed in SAP Business One.
    Let me know if you get stuck. Remember the above is an example and will need to be changed to use your tables and fields as required. The basic idea is to move across by one column with each select statement. So for example the first select statement does the CURRENT column, the second one the 30DAYS column, and so on.
    Kind regards
    Peter Juby

  • How to add a new metadata field to iPhoto where new field is calculated as age in years and month based on a specific date and the date photo was taken ? I want to calculate and display the age of my two kids on every photo.

    Hi
    How can I add 2 new metadata-fields to every photo in iPhoto ?
    The new fields should state the age of my kids in years and months based on the date that they were born and the date that photo is taken.
    Exampel:
    My son is born 01.01.2010
    My daughter is born 01.01.2012
    Photo taken by data
    Aage of son
    Aage of daughter
    01.07.2011
    1 year 6 month
    not born yet
    01.01.2014
    4 year 0 month
    2 year 0 month
    I would like to be able to search by kids age and get the info displayed when doing slideshows.
    How to do this in iPhoto ?
    Any alternatives to accomplish the same ?
    Kind regards

    It can't be done with iPhoto.  There are some DAM (digital asset management) applications that can write to other IPTC fields that iPhoto can't read. One such app is Media Pro 1.
    However you would have to calculate the age for each date and add it to one of the fields. There are online age calculators that can do that for you: Age Calculators
    If you go thru that much trouble then use iPhoto, make the calculations and add the age to the Description field.  Then you can use Smart Albums to search for 1year 6 month text.
    OT

  • SQL Query base Finish goods year wise report

    Hi
    I want to make query base year wise report  of Finish Goods.
    example like :
    Item Name     Year2010-11                           Year2011-12
       abc         Sep   Oct   Nov                 Sep    Oct   Nov 
        xyz        5     0      10                   2    5      0
    Why this report is need to me because i want to see How old Finish Goods are in the Stock. so that when a delivery make, the person can delivery from old stock first.
    Our FY is from September to August
    Please help me
    Regards,
    Mizan
    Edited by: mizan700 on Nov 15, 2011 3:28 PM

    Hi Eva,
    As Sybrand mentioned, you can't create DDL inside a procedure, and you probably don't need a temporary table. Temporary tables in SQL server used to be used to create a read consistent view for the duration of the procedure, but Oracle's multi version concurrent consistency model eliminates this as a need in all but the most remote cases.
    Your create table only seems to be used to take arguments from the user, which I don't see in your code.
    If I am looking at your code correctly, all you really want to ask the database is the following:
    select nvl(sum(dc.daily_count),0)
      from daily_counts_summary dc, branch br, division div
      where dc.branch_ky = br.branch_ky
        and br.division_ky = div.division_ky
        and dc.transaction_dt = t.trndt
        and dc.commission_cd = 'R'
        and div.division_ky = nvl(v_div_ky,div.division_ky)
        and dc.member_type_cd, 'P'
        and dc.expiration_dt between v_exp_start_dt and v_exp_end_dt;You can do this in Crystal Reports by writing a procedure that has an out parameter of type sys_refcursor. All you have to do is:
    create or replace procedure my_proc(p_curs in out sys_refcursor,v_exp_start_dt date,v_exp_end_dt date) is
    begin
      open p_cur for
    select nvl(sum(dc.daily_count),0)
      from daily_counts_summary dc, branch br, division div
      where dc.branch_ky = br.branch_ky
        and br.division_ky = div.division_ky
        and dc.transaction_dt = t.trndt
        and dc.commission_cd = 'R'
        and div.division_ky = nvl(v_div_ky,div.division_ky)
        and dc.member_type_cd, 'P'
        and dc.expiration_dt between v_exp_start_dt and v_exp_end_dt;
    end;
    /...or something close to that, with perhaps calls to your date functions to extract what you need.
    You also have several syntax errors in your code. I would recommend you get two books if your are going to work with Oracle:
    Anything by Tom Kyte
    Anything by Steven Feuerstein
    These would both be available on amazon.com
    HTH,
    Steve

  • Age in years

    Hi there,
    I want to select person DOB from a table with the difference between todays date.
    or in otherwords, I need to know about person birthdates before one years of their date of birth.
    Like if someone born in ((1943 - sysdate)-1) = 59 years
    I am doing it like
    select
    ((to_char(sysdate,'yyyy'))-(to_char(p.birth_date,'yyyy'))) Age from person p
    But its giving me the wrong results if someone born in 01/01/1943 or someone born in 1st of Jan in any year.
    Thanks

    Do you want the age of a person minus one year? If so, maybe following will work
    select
    floor(months_between(sysdate,p.birth_date)/12) age,
    floor(months_between(sysdate,p.birth_date)/12)+1 ageplusone,
    floor(months_between(sysdate,p.birth_date)/12)-1 ageminusone
    from ......
    Anna

Maybe you are looking for

  • Macbook Pro hard disk full, how do i store Movie files externally

    I have just freed some space, as I was unable to add any new files or Apps. How can i store my movies elsewhere? i am not bothered about a back up copy, just another storage area. I use them and play via PS3. I think i have used about 250gb on my Int

  • AJAX - How do we check if the response text returns a null value

    Hello, Could someone please help me with this issue? I am trying to disable a select box based on my responseText value. I need to check if my responseText is a null and disable my select if it is a null. Here is my code: if (xmlHttp.readyState==4)  

  • ODI - Set Based Transformations

    I'm a Business Intelligence SC and have a slide on ELT and ODI that highlights three reasons by performance is good. 1) Leverage Set-based transformations 2) Improved performance for loading, no network hop 3) Takes advantage of existing hardware I d

  • Can content be loaded from one PC into the iCloud and then accessed on another (new) PC?

    Can content that's loaded into the iCloud on one PC be accessed from the iCloud on another (new) PC?

  • Premiere Pro Export auf DVD

    Guten Tag, wer weiß Rat ? beim exportieren der fertigen Sequenz auf DVD , wird das Video am Fernsehgerät nur schwarz/weiß wiedergegeben. was habe ich falsch gemacht ? beim abspielen am PC ist es farbig , dies nur als Zusatzinfo ! Vielen Dank im vorau