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. Query doubt.....(Urgent need plz hlp me),

Query doubt.....(Urgent need plz hlp me),

Scheduled Pinned Locked Moved Database
databasequestion
4 Posts 3 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.
  • M Offline
    M Offline
    Member 3879881
    wrote on last edited by
    #1

    Hi i am week in query, plz solve my probs..., the following queries,that first query and second query both are working..., Now my question is, What are the fields, i am getting in the two queries those want to show in single query..., Means,in first query ur giving date in that it want to take the year only and check with tblmonthhourdetails.sdate and same time the tblmonthhourdetails empid want to equal with the employeemaster.empid ------------------------------------------------------------------ SELECT dbo.tblEmployeeMaster.empId, dbo.tblEmployeeMaster.empName, dbo.tblTimeCardmain.carddate, dbo.tblTimeCardmain.reportingtime, dbo.tblTimeCardmain.leavingtime, dbo.tblSalaryDetails.Whrs, dbo.tblTimeCardmain.shift, dbo.tblTimeCardmain.projectid FROM dbo.tblEmployeeMaster INNER JOIN dbo.tblTimeCardmain ON dbo.tblEmployeeMaster.empId = dbo.tblTimeCardmain.empid INNER JOIN dbo.tblSalaryDetails ON dbo.tblEmployeeMaster.empId = dbo.tblSalaryDetails.EmpID WHERE dbo.tblTimeCardmain.carddate = '5/2/2007' AND dbo.tblTimeCardmain.app1 = 1 AND dbo.tblTimeCardmain.projectid = 100 ----------------------------------------------------------------------- SELECT SUM(MedicalLeave) AS Ml, SUM(AnnualLeave) AS AL, EmpId FROM dbo.tblMonthHourDetails WHERE (DATEPART(YYYY, SDate) = 2007) GROUP BY EmpId, SDate ----------------------------------------------------------------------- Plz hlp me..., -- modified at 1:05 Thursday 14th June, 2007

    Magi

    A A 2 Replies Last reply
    0
    • M Member 3879881

      Hi i am week in query, plz solve my probs..., the following queries,that first query and second query both are working..., Now my question is, What are the fields, i am getting in the two queries those want to show in single query..., Means,in first query ur giving date in that it want to take the year only and check with tblmonthhourdetails.sdate and same time the tblmonthhourdetails empid want to equal with the employeemaster.empid ------------------------------------------------------------------ SELECT dbo.tblEmployeeMaster.empId, dbo.tblEmployeeMaster.empName, dbo.tblTimeCardmain.carddate, dbo.tblTimeCardmain.reportingtime, dbo.tblTimeCardmain.leavingtime, dbo.tblSalaryDetails.Whrs, dbo.tblTimeCardmain.shift, dbo.tblTimeCardmain.projectid FROM dbo.tblEmployeeMaster INNER JOIN dbo.tblTimeCardmain ON dbo.tblEmployeeMaster.empId = dbo.tblTimeCardmain.empid INNER JOIN dbo.tblSalaryDetails ON dbo.tblEmployeeMaster.empId = dbo.tblSalaryDetails.EmpID WHERE dbo.tblTimeCardmain.carddate = '5/2/2007' AND dbo.tblTimeCardmain.app1 = 1 AND dbo.tblTimeCardmain.projectid = 100 ----------------------------------------------------------------------- SELECT SUM(MedicalLeave) AS Ml, SUM(AnnualLeave) AS AL, EmpId FROM dbo.tblMonthHourDetails WHERE (DATEPART(YYYY, SDate) = 2007) GROUP BY EmpId, SDate ----------------------------------------------------------------------- Plz hlp me..., -- modified at 1:05 Thursday 14th June, 2007

      Magi

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      Hi Magi Try this:

      SELECT EM.empId, EM.empName, TC.carddate, TC.reportingtime,
        TC.leavingtime, SD.Whrs, TC.shift, TC.projectid,
        (SELECT SUM(MedicalLeave) FROM dbo.tblMonthHourDetails MHD
          WHERE MHD.EmpId = EM.empId AND YEAR(MHD.SDate) = 2007) AS ML,
        (SELECT SUM(AnnualLeave) FROM dbo.tblMonthHourDetails MHD
          WHERE MHD.EmpId = EM.empId AND YEAR(MHD.SDate) = 2007) AS AL
      FROM dbo.tblEmployeeMaster EM
      INNER JOIN dbo.tblTimeCardmain TC
      ON EM.empId = TC.empid
      INNER JOIN dbo.tblSalaryDetails SD
      ON EM.empId = SD.EmpID 
      WHERE TC.carddate = '5/2/2007' 
      AND TC.app1 = 1
      AND TC.projectid = 100
      

      I have used table aliases (EM, TC, etc) to make your query more readable. Correlated sub-queries are used to get the medical and annual leave. Regards Andy

      M 1 Reply Last reply
      0
      • M Member 3879881

        Hi i am week in query, plz solve my probs..., the following queries,that first query and second query both are working..., Now my question is, What are the fields, i am getting in the two queries those want to show in single query..., Means,in first query ur giving date in that it want to take the year only and check with tblmonthhourdetails.sdate and same time the tblmonthhourdetails empid want to equal with the employeemaster.empid ------------------------------------------------------------------ SELECT dbo.tblEmployeeMaster.empId, dbo.tblEmployeeMaster.empName, dbo.tblTimeCardmain.carddate, dbo.tblTimeCardmain.reportingtime, dbo.tblTimeCardmain.leavingtime, dbo.tblSalaryDetails.Whrs, dbo.tblTimeCardmain.shift, dbo.tblTimeCardmain.projectid FROM dbo.tblEmployeeMaster INNER JOIN dbo.tblTimeCardmain ON dbo.tblEmployeeMaster.empId = dbo.tblTimeCardmain.empid INNER JOIN dbo.tblSalaryDetails ON dbo.tblEmployeeMaster.empId = dbo.tblSalaryDetails.EmpID WHERE dbo.tblTimeCardmain.carddate = '5/2/2007' AND dbo.tblTimeCardmain.app1 = 1 AND dbo.tblTimeCardmain.projectid = 100 ----------------------------------------------------------------------- SELECT SUM(MedicalLeave) AS Ml, SUM(AnnualLeave) AS AL, EmpId FROM dbo.tblMonthHourDetails WHERE (DATEPART(YYYY, SDate) = 2007) GROUP BY EmpId, SDate ----------------------------------------------------------------------- Plz hlp me..., -- modified at 1:05 Thursday 14th June, 2007

        Magi

        A Offline
        A Offline
        Andy M
        wrote on last edited by
        #3

        Magh_M wrote:

        Query doubt.

        You have a question, not a doubt.

        1 Reply Last reply
        0
        • A andyharman

          Hi Magi Try this:

          SELECT EM.empId, EM.empName, TC.carddate, TC.reportingtime,
            TC.leavingtime, SD.Whrs, TC.shift, TC.projectid,
            (SELECT SUM(MedicalLeave) FROM dbo.tblMonthHourDetails MHD
              WHERE MHD.EmpId = EM.empId AND YEAR(MHD.SDate) = 2007) AS ML,
            (SELECT SUM(AnnualLeave) FROM dbo.tblMonthHourDetails MHD
              WHERE MHD.EmpId = EM.empId AND YEAR(MHD.SDate) = 2007) AS AL
          FROM dbo.tblEmployeeMaster EM
          INNER JOIN dbo.tblTimeCardmain TC
          ON EM.empId = TC.empid
          INNER JOIN dbo.tblSalaryDetails SD
          ON EM.empId = SD.EmpID 
          WHERE TC.carddate = '5/2/2007' 
          AND TC.app1 = 1
          AND TC.projectid = 100
          

          I have used table aliases (EM, TC, etc) to make your query more readable. Correlated sub-queries are used to get the medical and annual leave. Regards Andy

          M Offline
          M Offline
          Member 3879881
          wrote on last edited by
          #4

          Thanks lot..., Its working cool, Keep in touch, Take care,

          Magi

          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