Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Find Date between two Dates

Find Date between two Dates

Scheduled Pinned Locked Moved Database
databasequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robymon
    wrote on last edited by
    #1

    I created two tables 1) Attendance 2) Leave 1) Attendance table structure EmpID int Att_Date Datetime 2) Leave table Structure EmpID int LeaveID int LeaveFrom Datetime LeaveTo Datetime While taking the Attendance i want to check whether this employee taken any leave on that day(Attendance day). How can i write a sql for this. Eg: Attendance Date: 30/03/2012 Leave taken this Employee is 02/03/2012 - 05/03/2012 28/03/2012 - 31/03/2012 How can i write a sql to check this without any cursor.

    J 1 Reply Last reply
    0
    • R Robymon

      I created two tables 1) Attendance 2) Leave 1) Attendance table structure EmpID int Att_Date Datetime 2) Leave table Structure EmpID int LeaveID int LeaveFrom Datetime LeaveTo Datetime While taking the Attendance i want to check whether this employee taken any leave on that day(Attendance day). How can i write a sql for this. Eg: Attendance Date: 30/03/2012 Leave taken this Employee is 02/03/2012 - 05/03/2012 28/03/2012 - 31/03/2012 How can i write a sql to check this without any cursor.

      J Offline
      J Offline
      JamesAbbott
      wrote on last edited by
      #2

      I'm not 100% sure what you're after, I'll assume you want to find any records in the "leave" table for the attendance table.

      SELECT a1.EmpID, COUNT(l1.LeaveID) as LeaveRecords FROM
      Attendance a1 LEFT JOIN
      Leave l1 ON l1.EmpID = a1.EmpID AND a1.Att_Date BETWEEN l1.LeaveFrom AND l1.LeaveTo
      GROUP BY a1.EmpID

      Does that suit your needs? The above would return a list of emp attendances and the no of leave records for that attendance date.

      R 1 Reply Last reply
      0
      • J JamesAbbott

        I'm not 100% sure what you're after, I'll assume you want to find any records in the "leave" table for the attendance table.

        SELECT a1.EmpID, COUNT(l1.LeaveID) as LeaveRecords FROM
        Attendance a1 LEFT JOIN
        Leave l1 ON l1.EmpID = a1.EmpID AND a1.Att_Date BETWEEN l1.LeaveFrom AND l1.LeaveTo
        GROUP BY a1.EmpID

        Does that suit your needs? The above would return a list of emp attendances and the no of leave records for that attendance date.

        R Offline
        R Offline
        Robymon
        wrote on last edited by
        #3

        Thank you very much...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups