Problem: query to find employees at one plant for specified year

Problem: how to determine if an employee was working at a specific plant during a specific year using this limited amount of data in a "job changes" table. No matter what I've tried, I keep getting the wrong number of records and it's driving me nuts. I thought this would be a simple query but it's not (for me anyway!) so I need a "clue" to point me in the right direction. Help? :-)
Sample records:
EMPLID  PLANT   EFF_DATE    HIRE_DATE   TERM_DATE
123456  23      01-JAN-00   22-MAR-88   NULL
123456  29      30-JUL-02   22-MAR-88   NULL
123456  22      21-AUG-03   22-MAR-88   NULL
456789  29      11-JUL-01   11-JUL-01   NULL
456789  22      30-JUL-03   11-JUL-01   NULLFor example, how do I write the query so that employee 123456 will show up for years 1999 and 2001 in plant 23?

Here is an example:
SQL> SELECT * FROM EMP;
    EMPLID      PLANT EFF_DATE    HIRE_DATE   TERM_DATE
    123456         23 01-JAN-2000 22-MAR-1988
    123456         29 30-JUL-2002 22-MAR-1988
    123456         22 21-AUG-2003 22-MAR-1988
    456789         29 11-JUL-2001 11-JUL-2001
    456789         22 30-JUL-2003 11-JUL-2001
5 rows selected.
SQL> SELECT A.EMPLID,A.PLANT,A.EFF_DATE,A.END_DATE FROM
  2  (SELECT EMPLID,PLANT,EFF_DATE,LEAD(EFF_DATE,1) OVER(ORDER BY EMPLID,EFF_DATE) -1 END_DATE,
  3  HIRE_DATE FROM EMP
  4  WHERE EMPLID=123456
  5  ORDER BY EMPLID) A
  6  WHERE A.EFF_DATE >= TO_DATE('01-JAN-1999','DD-MON-YYYY')
  7  AND A.EFF_DATE <= TO_DATE('31-DEC-2001','DD-MON-YYYY')
  8  AND TO_DATE('31-DEC-2001','DD-MON-YYYY') <= END_DATE;
    EMPLID      PLANT EFF_DATE    END_DATE
    123456         23 01-JAN-2000 29-JUL-2002
1 row selected.

Similar Messages

  • Query to find employees who are managers for 3 or more employees

    Hi,
    I am using emp table in scott schema for this query.
    select * from emp
    where empno in
    (select e.mgr
    from emp e, emp m
    where e.mgr = m.empno
    group by e.mgr
    having count(*) >= 3);
    It gives all employee details where he is manager for more than or equal 3 employees. Please suggest all possible queries which gives same output.
    Thanks
    Raghu

    select * from emp
    select a.empno, a.ename , a.mgr, b.ename reported_to
    from emp a, emp b
    where a.mgr = b.empno
    --start with keyword
    SELECT empno, ename, mgr, LEVEL
    FROM emp
    START WITH empno = 7788
    CONNECT BY PRIOR empno = mgr
    ORDER siblings BY ename;
    -- employee reported to
    SELECT ename || ' reports to ' ||
    PRIOR ename "Walk Top Down"
    FROM emp
    START WITH ename = 'KING'
    CONNECT BY PRIOR empno = mgr
    -- use of PRIOR in different places
    SELECT ename || ' reports to ' ||
    PRIOR ename "Walk Top Down"
    FROM emp
    START WITH ename = 'KING' --'SCOTT'
    CONNECT BY PRIOR empno = mgr
    -- using prior type 2
    SELECT ename || ' reports to ' ||
    PRIOR ename "Walk Top Down"
    FROM emp
    START WITH ename = 'CLARK' --'SCOTT'
    CONNECT BY empno = PRIOR mgr
    -- top down
    SELECT empno, ename, job, mgr
    FROM emp
    START WITH ename = 'SMITH'
    CONNECT BY PRIOR mgr = empno ;
    -- bottom up
    SELECT empno, ename, job, mgr
    FROM emp
    START WITH ename = 'SMITH'
    CONNECT BY PRIOR empno = mgr ;
    --level chart
    SELECT LPAD(ename, LENGTH(ename) + (LEVEL * 2 ) - 1, '_ '), level
    AS org_chart
    FROM emp
    START WITH ename='KING' --'SCOTT'
    CONNECT BY PRIOR empno = mgr
    --Using WHERE clause to eliminate a node.
    SELECT deptno, empno,ename, job, sal
    FROM emp
    WHERE ename != 'FORD'
    START WITH mgr IS NULL
    CONNECT BY PRIOR empno = mgr;
    -- Using CONNECT BY clause to eliminate a branch.
    SELECT deptno, empno,ename, job, sal
    FROM emp
    START WITH mgr IS NULL
    CONNECT BY PRIOR empno = mgr
    AND ename != 'FORD'
    SELECT EName "Employee",
    LEVEL,
    SYS_CONNECT_BY_PATH(ename, ' /') "Path"
    FROM emp
    START WITH mgr is null
    CONNECT BY PRIOR empno = mgr;
    -- 10g features
    -- connect by isleaf
    Select Ename "Employee", Connect_by_isleaf "IsLeaf", Level,
    Sys_connect_by_path (Ename, ' /') "Path"
    From Emp
    Start With Mgr Is Null
    Connect By Prior Empno = Mgr;
    -- connect by iscycle
    SELECT EName "Employee",
    CONNECT_BY_ISLEAF "IsLeaf",
    CONNECT_BY_ISCYCLE "IsCycle",
    LEVEL,
    SYS_CONNECT_BY_PATH(ename, ' /') "Path"
    FROM emp
    START WITH mgr is null
    CONNECT BY nocycle prior empno = mgr;
    -- connect by root
    SELECT ename "Employee", CONNECT_BY_ROOT ename "Manager",
    LEVEL-1 "Pathlen", SYS_CONNECT_BY_PATH(ename, '/') "Path"
    FROM emp
    WHERE LEVEL > 1 and deptno = 10
    CONNECT BY PRIOR empno = mgr;

  • Query to find Employee Salary Details

    Hi,
    Could anyone help in writing the query to find employee salary details.
    Thanks in advance.

    This should get you started:
    SELECT papf.full_name
    ,papf.email_address
    ,ppp.proposed_salary_n salary
    FROM per_pay_proposals ppp
    ,per_all_assignments_f paaf
    ,per_all_people_f papf
    WHERE ppp.assignment_id = paaf.assignment_id
    AND paaf.assignment_type = 'E'
    AND paaf.primary_flag = 'Y'
    AND paaf.person_id = papf.person_id
    AND nvl(papf.current_employee_flag, 'N') = 'Y'
    AND trunc(sysdate) BETWEEN
    ppp.change_date AND ppp.date_to
    AND trunc(sysdate) BETWEEN
    paaf.effective_start_date AND paaf.effective_end_date
    AND trunc(sysdate) BETWEEN
    papf.effective_start_date AND papf.effective_end_date;

  • I need advise and help with this problem . First , I have been with Mac for many years ( 14 to be exact ) I do have some knowledge and understanding of Apple product . At the present time I'm having lots of problems with the router so I was looking in to

    I need advise and help with this problem .
    First , I have been with Mac for many years ( 14 to be exact ) I do have some knowledge and understanding of Apple product .
    At the present time I'm having lots of problems with the router so I was looking in to some info , and come across one web site regarding : port forwarding , IP addresses .
    In my frustration , amongst lots of open web pages tutorials and other useless information , I come across innocent looking link and software to installed called Genieo , which suppose to help with any router .
    Software ask for permission to install , and about 30 % in , my instinct was telling me , there is something not right . I stop installation . Delete everything , look for any
    trace in Spotlight , Library . Nothing could be find .
    Now , every time I open Safari , Firefox or Chrome , it will open in my home page , but when I start looking for something in steed of Google page , there is
    ''search.genieo.com'' page acting like a Google . I try again to get raid of this but I can not find solution .
    With more research , again using genieo.com search eng. there is lots of articles and warnings . From that I learn do not use uninstall software , because doing this will install more things where it come from.
    I do have AppleCare support but its to late to phone them , so maybe there some people with knowledge , how to get this of my computer
    Any help is welcome , English is my learned language , you may notice this , so I'm not that quick with the respond

    Genieo definitely doesn't help with your router. It's just adware, and has no benefit to you at all. They scammed you so that they could display their ads on your computer.
    To remove it, see:
    http://www.thesafemac.com/arg-genieo/
    Do not use the Genieo uninstaller!

  • I downloaded Firefox 7 and when I click on the browser icon nothing happens, the browser does not load on desktop.I had no problems with Firefox 4 I had been using for several years and liked very much

    I downloaded Firefox 7 and when I click on the browser icon nothing happens, the browser does not load on desktop.I had no problems with Firefox 4 I had been using for several years and liked very much

    Most people have no problems with installing firefox as an upgrade, but there are quite a few things that can cause problems. Please have a look at the articles
    * [[software Update Failed]] <-- clickable link (blue ) --
    * [[firefox will not start]]
    * [[firefox does not work]]
    Post back after you read them and say what you tried. Have you ensured you used an admin account, possibly needing to check the UAC setting, and that security software is not blocking the changes. You should certainly try starting in firefox's [[safe mode]] either from a menu/icon option or by holding the shift key as you attempt to run firefox.
    Is the browser icon you see on the desktop, and a firefox icon ?

  • Query to find employee of the month in year

    HI,
    Can anyone please help me in writing the following queries on Northwind database.
    1.We are going to motivate employees by creating 'Employee of Month' (employee who has made highest sale). Create Employee of Month List for year 1997. 
    2.We want to know how our products’ sales differ from each month. Get the list product which
    we sold the most and which we sold the least in quantity for each month of 1997.

    And for the second problem try:
    WITH cte
    AS (
    SELECT OD.ProductID
    ,SUM(OD.Quantity) AS SoldQty
    ,datepart(month, O.OrderDate) AS MonthNumber
    ,datename(month, O.OrderDate) AS [Month Name]
    FROM dbo.Orders O
    INNER JOIN dbo.[Order Details] OD ON O.OrderID = OD.OrderID
    WHERE O.OrderDate >= '19970101'
    AND O.OrderDate < '19980101'
    GROUP BY datepart(month, O.OrderDate)
    ,datename(month, O.OrderDate)
    ,OD.ProductID
    ,cte1
    AS (
    SELECT P.ProductName
    ,P.ProductID
    ,cte.SoldQty
    ,cte.MonthNumber
    ,cte.[Month Name]
    ,ROW_NUMBER() OVER (
    PARTITION BY cte.MonthNumber ORDER BY SoldQty
    ) AS RnMin
    ,ROW_NUMBER() OVER (
    PARTITION BY cte.MonthNumber ORDER BY SoldQty DESC
    ) AS RnMax
    FROM cte
    INNER JOIN dbo.Products P ON cte.ProductID = P.ProductID
    SELECT [Month Name]
    ,MIN(CASE
    WHEN RnMin = 1
    THEN ProductName
    END) AS [Least Sold Product]
    ,MIN(CASE
    WHEN RnMin = 1
    THEN SoldQty
    END) AS [Least Sold Qty]
    ,MIN(CASE
    WHEN RnMax = 1
    THEN ProductName
    END) AS [Best Sold Product]
    ,MIN(CASE
    WHEN RnMax = 1
    THEN SoldQty
    END) AS [Best Sold Qty]
    FROM cte1
    GROUP BY [MonthNumber]
    ,[Month Name]
    ORDER BY [MonthNumber]
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Query to find Employee's Business group name

    Hi,
    I am new to HRMS module.
    I want to find the employee's (from per_all_people_f) business group details.
    I found a base table HR_ALL_ORGANIZATION_UNITS, but there are many records in that table with the same business_group_id as that by itself isnt a unique key.
    Could some one assist me in finding the link between employees and their BG.
    Thanks.

    the business group details are stored in the table "*PER_BUSINESS_GROUPS_PERF*" So you can use the following clause:
    where PER_ALL_PEOPLE_F.BUSINESS_GROUP_ID = PER_BUSINESS_GROUPS_PERF.BUSINESS_GROUP_ID
    Good Luck,

  • Query to find employee salary details in HRMS

    Hi,
    Could anyone one provide me the query to get the salary details of an employee.
    Thanks.

    Hi,
    Hope this work for you.
    SELECT pap.last_name last_name
    ,pap.first_name first_name
    ,pap.employee_number employee_id
    ,hlu2.meaning ethnic_origin
    ,hlu1.meaning eeo_category
    ,hlu5.meaning veteran_status
    ,pap.sex sex
    ,ROUND(pro.proposed_salary_n, 2) current_salary
    ,ROUND(pro.proposed_salary_n * ppb.pay_annualization_factor) current_yearly_salary
    ,pg.NAME grade
    ,pj.NAME job_name
    ,pjd.segment3 business_unit
    ,pjd.segment4 FUNCTION
    ,pjd.segment5 designation
    ,pjd.segment2 job_group
    ,pos.date_start hire_date
    ,NVL(pos.actual_termination_date, hr_general.end_of_time) termination_date
    ,hl.location_code LOCATION
    ,pap.full_name
    ,pj.job_information3 flsa_code
    ,hlu4.meaning employment_category_meaning
    ,pap.effective_start_date p_effective_start_date
    ,pap.effective_end_date p_effective_end_date
    ,paa.effective_start_date a_effective_start_date
    ,paa.effective_end_date a_effective_end_date
    ,pro.from_change_date s_effective_from_date
    ,NVL(pro.to_change_date, hr_general.end_of_time) s_effective_to_date
    ,pap.current_employee_flag
    FROM per_all_people_f pap
    ,per_all_assignments_f paa
    ,per_periods_of_service pos
    ,(SELECT pro1.approved
    ,pro1.assignment_id
    ,pro1.change_date from_change_date
    , pro_next.change_date - 1 to_change_date
    ,pro1.multiple_components
    ,pro1.last_change_date
    ,pro1.proposed_salary_n
    ,pro1.forced_ranking
    ,pro1.last_updated_by
    ,pro1.last_update_date
    ,pro1.event_id
    ,pro1.performance_review_id
    ,pro1.pay_proposal_id
    FROM per_pay_proposals pro1
    ,per_pay_proposals pro_next
    WHERE pro1.assignment_id = pro_next.assignment_id(+)
    AND pro1.change_date = pro_next.last_change_date(+)) pro
    ,per_jobs pj
    ,per_job_definitions pjd
    ,hr_locations hl
    ,per_grades pg
    ,(SELECT *
    FROM hr_lookups
    WHERE lookup_type = 'US_EEO1_JOB_CATEGORIES') hlu1
    ,(SELECT *
    FROM hr_lookups
    WHERE lookup_type = 'US_ETHNIC_GROUP') hlu2
    ,(SELECT *
    FROM hr_lookups
    WHERE lookup_type = 'US_EXEMPT_NON_EXEMPT') hlu3
    ,(SELECT *
    FROM hr_lookups
    WHERE lookup_type = 'EMP_CAT') hlu4
    ,(SELECT meaning
    ,lookup_code
    FROM hr_lookups
    WHERE lookup_type LIKE 'US_VETERAN_STATUS') hlu5
    ,per_pay_bases ppb
    ,(SELECT *
    FROM per_addresses
    WHERE primary_flag = 'Y'
    AND address_type = 'H'
    AND ( date_to IS NULL
    OR date_to > SYSDATE)) addr
    WHERE pap.person_id = paa.person_id
    AND paa.assignment_id = pro.assignment_id
    AND paa.job_id = pj.job_id
    AND paa.location_id = hl.location_id
    AND paa.grade_id = pg.grade_id(+)
    AND pos.person_id = pap.person_id
    AND ppb.pay_basis_id = paa.pay_basis_id
    AND pj.job_information1 = hlu1.lookup_code
    AND pj.job_definition_id = pjd.job_definition_id
    AND pap.per_information1 = hlu2.lookup_code(+)
    AND pap.per_information5 = hlu5.lookup_code(+)
    AND pj.job_information3 = hlu3.lookup_code(+)
    AND paa.employment_category = hlu4.lookup_code
    AND addr.person_id(+) = pap.person_id

  • Query to find employee annual salary or pay rate for a pay period (Bi-Week)

    Hi Guru's,
    need your help for finding annual salary or pay rate for pay period for an employee.
    I have below query returning some thousand line which I cant understand. Can someone correct the query please.
    SELECT ppp.proposed_salary_n salary From per_pay_proposals ppp,apps.per_all_people_f papf,apps.per_all_assignments_f paaf,apps.per_all_people_f papf1 WHERE papf.person_id = paaf.person_id AND paaf.primary_flag = 'Y' AND paaf.assignment_type = 'E' AND paaf.supervisor_id = papf1.person_id AND papf1.current_employee_flag = 'Y'AND papf.business_group_id = paaf.business_group_id AND SYSDATE BETWEEN papf.effective_start_date and papf.effective_end_date AND SYSDATE BETWEEN paaf.effective_start_date AND paaf.effective_end_date AND SYSDATE BETWEEN papf1.effective_start_date AND papf1.effective_end_date AND papf.employee_number='1234';
    SALARY
    17.4346
    16.0846
    17.4346
    13.78
    13.78
    15.07
    13.78
    13.78
    13.78
    3305.59
    14.859
    SALARY
    5507.25
    2731.01
    2690.51
    13.78
    13.35
    13.35
    1960
    4192
         17
    4927
    2525.02
    SALARY
    2652
    13.35
    15.07
    2686.67
    2964
    13.78
    17.4635
    20.4981
    16.0846
    13.78
    17.4635
    SALARY
    2666.68
    13.78
    15.07
    13.78
    16.0846
    17.4635
    4353.99
    4562.51
    17.4346
    16.0846
    6727.41
    SALARY
    2780.99
         20
    17.4346
    16.0846
    2970
    2315.01
    17.4635
    2629.85
    14.5705
    5635
    17.4346
    Thanks
    Sandeep

    I used table hrpy_rgdir  to get sequence number for the given pernr, payroll area and dates.
    Using the sequence number, I am calling Function PYXX_READ_PAYROLL_RESULT to extract the payroll results.
    SELECT * INTO CORRESPONDING FIELDS OF TABLE it_hrpy_rgdir
      FROM hrpy_rgdir
      WHERE srtza = 'A'             
        AND paydt IN sopaydt
        AND abkrs IN soabkrs
        AND pernr IN sopernr.
    LOOP AT it_hrpy_rgdir.
      PERFORM get_rt USING it_hrpy_rgdir-pernr it_hrpy_rgdir-seqnr.
    ENDLOOP.
    *&      Form  get_rt
    *       text
    *      -->PERNR      text
    *      -->SEQNR      text
    FORM get_rt USING pernr seqnr.
      CLEAR: it_payroll_result.
      CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT'
        EXPORTING
          clusterid                    = 'RQ'
          employeenumber               = pernr
          sequencenumber               = seqnr
        CHANGING
          payroll_result               = it_payroll_result
        EXCEPTIONS
          illegal_isocode_or_clusterid = 1
          error_generating_import      = 2
          import_mismatch_error        = 3
          subpool_dir_full             = 4
          no_read_authority            = 5
          no_record_found              = 6
          versions_do_not_match        = 7
          error_reading_archive        = 8
          error_reading_relid          = 9
          OTHERS                       = 10.
    ENDFORM.                   
    For any period, the function module just returns sy-subrc = 6 [no_record_found].
    We are on Australian Payroll.  Could you please let me know what I might be missing or is there an alternative way of getting the information ?
    Thank you

  • Query to find employee competence score and rating against each competence

    Hi Guys,
    I am looking for a query to retrieve the below information -
    1. Job competency requirement value ( stored in competency requirement screen)
    2. Actual competenct value ( stored in competence profile)
    Basically from these two values, we like to figure out the competency gap for the employee.
    Appreciate your help!
    thanks,
    AB

    any help guru's!!!!

  • Query to find employees responsibilties in Department

    Dear All
    i need query which can give me list of responsibilties of users in a particular department.
    i am unable to link the organization id or the person id with responsibilty table or fnd_user table.
    Thanks

    Dear All
    i need query which can give me list of responsibilties of users in a particular department.
    i am unable to link the organization id or the person id with responsibilty table or fnd_user table.
    Thanks

  • Sql query to find answered and received calls for month or day

    Hi  experts !
    1.Any one help in finding out the received, answered and missed ,transfered  in  /  out  calls  in  UCCE  using SQL query for a particular month or day.
    2. We have some  custom report templetes defined ,  need to  know  , how can we  write Sql  query  to  get those  values  from  custum reports.
    due to some issues,  cannot use  webview .

    Hi,
    there's no such thing as reporting "for a particular Team". Teams in ICM are for administration purposes only (to have grouping of agents). ICM does not count the number of calls received by "teams". If there is a report in Webview "by team", it's always by agent. Try to run the report against a team once and then try to remove certain agents from that team - you'll see the difference.
    What you are looking for is either reporting by Agent or by Agent/Skill group combination.
    Try to explore the
    - Agent_Half_Hour
    - Agent_Skill_Group_Half_Hour
    - Skill_Group_Half_Hour
    database views.
    The database schema documents are here:
    http://www.cisco.com/en/US/products/sw/custcosw/ps1844/prod_technical_reference_list.html
    Good luck.
    G.

  • Query to find the latest two transactions for each Group

    Hi All,
    Consider the following sets of records in a table test.
    Group---Tran_Dt---SlNo
    c1 10/10/2003 1
    c1 10/10/2003 2
    c1 10/10/2003 3
    c1 11/10/2003 1
    c2 10/10/2003 1
    c2 10/10/2003 2
    c2 11/10/2003 1
    c2 11/10/2003 2
    c2 11/10/2003 3
    c3 10/10/2003 1
    c3 10/10/2003 2
    c3 10/10/2003 3
    I want to list out the latest two transactions for each group irrespective of the slno and trans_dt as below:
    group tran_dt SlNo
    c1 11/10/2003 1
    c1 10/10/2003 3
    c2 11/10/2003 3
    c2 11/10/2003 2
    c3 10/10/2003 3
    c3 10/10/2003 2
    Any help on this would be appreciated.
    Thanks
    Walter Nicholas T

    Hi Walter,
    Please try following query.
    select Group,tran_dt,sino from
    select Group,tran_dt,sino,(DENSE_RANK()OVER (PARTITION BY Group ORDER BY tran_dt desc,sino desc)) rank from test
    ) where rank between 1 and 2
    Thanks,
    Samir

  • ODI metadata query to find source and Target table for Interface

    Hi Experts,
    Client is migrating there source from EBS 11.5.10 to R12. They are in ODI BIApps. 7952 version.Since,all there mappings are customized they are not bothering about support from Oracle as far as BIApps is concerned.
    Now,we need to know how many ODI mappings will be impacted when source EBS is migrating from 11.5.10 to R12 and so that we can only target those mappings accordingly.
    So,please provide me with below inputs:
    1) Any metadata query which will give me the source table and target table information's against an interface even-if the main interface source is another interface.
    2) What are the other stuffs I need to look from point of view of mapping changes when the source is upgrading.e.g. only source table change is enough or I need to look into other stuffs.I feel,it is boiling down to create a separate source adapter for R12.
    Regards,
    Snehotosh

    SELECT C.TABLE_NAME AS "Target Table Name",
         A.COL_NAME AS "Target Field Name",
         Wm_Concat(G.SOURCE_DT) AS "Target Data Type",
         Wm_Concat(G.LONGC) AS "Target Data Length",
         Wm_Concat(TXT) AS "Transformation Rule",
         Wm_Concat(DISTINCT F.TABLE_NAME) AS "Source Table Name",
         Wm_Concat(D.COL_NAME) AS "Source Field Name",
         Wm_Concat(D.SOURCE_DT) AS "Source Data Type",
         Wm_Concat(D.LONGC) AS "Source Data Length"
    FROM
         SNP_POP_COL A JOIN SNP_TXT_CROSSR B ON A.I_TXT_MAP=B.I_TXT
         JOIN SNP_POP C ON A.I_POP=C.I_POP
         JOIN SNP_TXT E ON A.I_TXT_MAP=E.I_TXT AND B.I_TXT=E.I_TXT
         LEFT OUTER JOIN SNP_COL D ON B.I_COL=D.I_COL
         LEFT OUTER JOIN SNP_TABLE F ON F.I_TABLE= D.I_TABLE
         LEFT JOIN SNP_COL G ON A.I_COL=G.I_COL
    WHERE POP_NAME = 'XXXXXXX'
    GROUP BY C.TABLE_NAME,A.COL_NAME ORDER BY 1

  • Find Employee Worked 7 Consecutive days

    Hello All,
    I have a view with following columns
    (EMP #, Dept #, Total hours worked, Date of the total hours, Current Pay period st date, Current Pay period end date, Previous pay period start date, Previous pay period start date, Next pay period st date, next pay period end date)
    I need a query to find employees who worked consecutively for 7 Days
    within a date range.
    Please let me know...
    Thanks,
    Kottee
    kotteeswaran

    DECLARE @StartDate DATETIME
    DECLARE @EndDate  DATETIME
    SET @StartDate = '11/1/2010'
    SET @EndDate ='11/10/2010'
    SELECT        VP_ALLTOTALS.PERSONNUM,
            MIN(VP_ALLTOTALS.APPLYDATE) AS StartDate,
            MAX(VP_ALLTOTALS.APPLYDATE) AS Enddate
    FROM        (
                SELECT    V.PERSONNUM,
                    V.APPLYDATE,
                    DATEDIFF(DAY, '17530101', VP_ALLTOTALS.APPLYDATE) - ROW_NUMBER() OVER (PARTITION BY VP_ALLTOTALS.PERSONNUM ORDER BY VP_ALLTOTALS.APPLYDATE) AS GroupID
                FROM    VP_ALLTOTALS V
                WHERE    VP_ALLTOTALS.APPLYDATE BETWEEN @StartDate AND @EndDate
            ) AS t
    GROUP BY    VP_ALLTOTALS.PERSONNUM,
            GroupID
    HAVING        COUNT(*) >= 7
    I'm getting following errors
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.PERSONNUM" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.PERSONNUM" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.PERSONNUM" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    And Many Thanks for PESO and RAMIREDDY...
    Thanks,
    kotteesh
    kotteeswaran

Maybe you are looking for

  • Hi. i purchased flightradar24 apps from my iPad. can i share the same app on my macbook?

    hi. i purchased flightradar24 apps from my iPad. can i share the same app on my macbook?

  • IPhone Car Adaptor

    I have a Griffin iTrip FM transmitter, and it plays on my mp3s and ipods but it won't for my iPhone and won't play in my friends car that has a direct auxillary input. Is there an FM transmitter out there that will play the music on the iPhone?

  • Help me to find a suitable new area in SAP to work on?

    Hi All, I am working in ABAP for the last 2 half years. Now i like to switch over from ABAP because i am not interested in coding. I can't move to functional area also because I don't have any domain experience like SD,MM.... . Please help me to find

  • Why is nothing happening on my MBP?

    Granted, I haven't used a Mac for a few years, but I got a MBP and am having trouble getting the apps to work. I'll just start with this question: I click on Time Machine and it asks if I want to set it up and I click "set up TM" ... and -- and -- no

  • SIIG SATA 4 channel PCI-M - problems

    All, Have a PowerMac G4 933 that I will be installing 4 SATA drives into. Purchased the SIIG SATA 4 channel PCI-M card (specific for Mac). Before installing SIIG card - system boots fine. Install card, system simply will not boot - screen stays dark,