Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:12:19+00:00 2026-06-13T04:12:19+00:00

please help in the following query Display Employee Name, Dept Name, Salary, Grade, Experience

  • 0

please help in the following query
Display Employee Name, Dept Name, Salary, Grade, Experience (EX: XX Years YY Months ZZ Days) for all the employees

ENAME     DNAME    SAL  GRADE      EXPERIENCE

SCOTT    RESEARCH  3000   4        12 Years 3 months 15 days

like this i need to get the output.

i have tried to write upto years but months,days i am not able to get.

select distinct ename,dname,sal,grade,
 (round((months_between(sysdate,hiredate)/12))||' years' EXP 
 from emp,salgrade,dept 
 where dept.deptno=emp.deptno and sal between losal and highsal;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:12:20+00:00Added an answer on June 13, 2026 at 4:12 am

    Here’s a T-SQL (SQL Server) solution which I’ve got working (based on tests so far). Sadly I don’t have an oracle instance to play on, but hopefully this shouldn’t be too hard to convert:

    declare @fromDate date = '2010-11-21'
    , @toDate date = getutcdate()
    
    --from date must be before to date
    declare @tempDate date
    if @toDate < @fromDate 
    begin
        set @tempDate = @toDate
        set @toDate = @fromDate
        set @fromDate = @tempDate
    end
    
    declare @fDD int = datepart(dd,@fromdate)
    , @tDD int = datepart(dd,@todate)
    , @fMM int = datepart(mm,@fromdate)
    , @tMM int = datepart(mm,@todate)
    , @fYYYY int = datepart(yyyy,@fromdate)
    , @tYYYY int = datepart(yyyy,@todate)
    , @y int, @m int, @d int
    
    --calc difference in years
    set @y = @tYYYY-@fyyyy
    if @fMM > @tMM or (@fMM=@tMM and @fDD > @tDD)
    begin
        set @y = @y - 1
        set @fYYYY = @fYYYY + @y
        set @tempDate = DATEADD(year,@y,@fromDate)
    end
    
    --calc remaining difference in months
    set @m = DATEDIFF(month,@tempDate,@toDate)
    if @tDD < @fDD 
    begin
        set @m = @m-1
        set @tempDate = DATEADD(month,@m,@tempDate)
    end
    
    --calc remaining difference in days
    set @d = DATEDIFF(day,@tempDate,@toDate)
    
    --display results in user friendly and grammatically correct way
    select cast(@y as nvarchar(3)) + N' year' + case when @y = 1 then N'' else N's' end + N' '
    + cast(@m as nvarchar(2)) + N' month' + case when @m = 1 then N'' else N's' end + N' '
    +  cast(@d as nvarchar(3)) + N' day' + case when @d = 1 then N'' else N's' end + N' '
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me generate the following query i've been struggling with for some time
can someone please help me with the following query i need to update a
Please help to improve the following query: UPDATE queries q SET query = (SELECT
Please help me to generate the following query. Say I have customer table and
The following query will display all Dewey Decimal numbers that have been duplicated in
Please help regarding the following issue. I have enabled the Block popup option in
Please help me with following, I have a database which contain strings ( e.g.
Please help with the following: I have an input file that is quite heterogeneous
Please help with the following error that I get with Spring Security 3.05 and
Please help me with following problem. In my android assets folder I have xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.