Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    7

    Unanswered: i have a little question

    hello every one
    i am new here and i have a question
    i have table like this

    PR_NO CHANG_DAT APPR_PER APPR_DAT
    6 01/07/2009 8 31/03/2009
    6 01/07/2008 8 31/03/2008
    6 01/07/2007 8 31/03/2007
    6 01/07/2006 10 31/03/2006
    6 01/07/2005 10 31/03/2005

    i want to get the recored on the row that max(chang_dat)
    when i make grouping and select max chang_dat it gives me many recoreds i want only the record on the max(chang_dat) which is
    6 01/07/2009 8 31/03/2009


    the sp which i wrote is

    create proc [dbo].[salary_career_appraisal_last_tst]
    @pr_no int
    as
    SELECT SAL_H.PR_NO, Max(SAL_H.CHANG_DAT) AS MaxOfCHANG_DAT, SAL_H.APPR_PER, SAL_H.APPR_DAT
    FROM SAL_H
    where pr_no = @pr_no
    group by pr_no , APPR_PER , APPR_DAT

    but it give me many recoreds
    thank you for your help

  2. #2
    Join Date
    Oct 2002
    Location
    Baghdad, Iraq
    Posts
    697
    Try:

    Code:
    create proc [dbo].[salary_career_appraisal_last_tst]
    @pr_no int
    as 
    SELECT PR_NO, CHANG_DAT, APPR_PER, APPR_DAT
    FROM SAL_H
    where pr_no = @pr_no and CHANG_DAT = (select max(chang_dat) from sal_h where pr_no = @pr_no))

  3. #3
    Join Date
    Oct 2009
    Posts
    7
    thank u very much it was very helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •