Extract Years from multiple columns and prepare a consolidated list

Hi Team,

I have an Employee table in below structure, and I want to create a list of years by taking all the distinct years from both the Start_Date and End_Date columns.

employee ( emp_id Number, Start_Date Date, End_Date Date, Status Varchar2(50) )

Please help me with your ideas.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    code sample of nitesht's answer to solve this in SAIL. 

     

    If you meant you wanted all unique years from both start and end dates together:

    load(
      local!startYears: {2011, 2012, 2012, 2013, 2028}, 
       /*use index(ri!employee, "Start_Date", {}) here */
      local!endYears: {2013, 2025, 2028, 2046}, 
       /*use index(ri!employee, "End_Date", {}) here */
      local!allYears: append(local!startYears, local!endYears),
      local!allUniqueYears: union(local!allYears, local!allYears),
      local!allUniqueYears
    )

     

    Similar code if you meant you wanted the unique start years and unique end years separately:

    load(
      local!startYears: {2011, 2012, 2012, 2013, 2028}, 
      /* use index(ri!employee, "Start_Date", {}) here */
      local!endYears: {2013, 2025, 2028, 2046, 2046, 2046}, 
      /* use index(ri!employee, "End_Date", {}) here */
      local!startUniqueYears: union(local!startYears, local!startYears),
      local!endUniqueYears: union(local!endYears, local!endYears),
      /*local!startUniqueYears*/
      local!endUniqueYears
    )

Reply
  • 0
    Certified Lead Developer

    code sample of nitesht's answer to solve this in SAIL. 

     

    If you meant you wanted all unique years from both start and end dates together:

    load(
      local!startYears: {2011, 2012, 2012, 2013, 2028}, 
       /*use index(ri!employee, "Start_Date", {}) here */
      local!endYears: {2013, 2025, 2028, 2046}, 
       /*use index(ri!employee, "End_Date", {}) here */
      local!allYears: append(local!startYears, local!endYears),
      local!allUniqueYears: union(local!allYears, local!allYears),
      local!allUniqueYears
    )

     

    Similar code if you meant you wanted the unique start years and unique end years separately:

    load(
      local!startYears: {2011, 2012, 2012, 2013, 2028}, 
      /* use index(ri!employee, "Start_Date", {}) here */
      local!endYears: {2013, 2025, 2028, 2046, 2046, 2046}, 
      /* use index(ri!employee, "End_Date", {}) here */
      local!startUniqueYears: union(local!startYears, local!startYears),
      local!endUniqueYears: union(local!endYears, local!endYears),
      /*local!startUniqueYears*/
      local!endUniqueYears
    )

Children
No Data