Select query with join

Posted by Rock_Monu under Sql Server on 7/27/2012 | Points: 10 | Views : 840 | Status : [Member] | Replies : 4
i have two table tbl_emp and tbl_emp_attendence have common field empid.now i want to that when i click submit button then basis on empid we get empname and empattendence .but empattendence has between startdate and enddate .
so plz give me good response.




Responses

Posted by: Pandians on: 7/27/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Check it out!
Create Proc Usp_GetEmployeeAtten

(
@EmpID VARCHAR(5),
@StartDate DATETIME,
@EndDate DATETIME
)As
Begin
Set Nocount On

Select E.Empname,EA.Empattendence From tbl_emp E With(Nolock) Join tbl_emp_attendence EA With(Nolock)
On (E.Empid = EA.Empid)
Where E.Empid = @EmpID
And EA.Empattendence Between @StartDate And @EndDate
End
Go
Exec Usp_GetEmployeeAtten @EmpID='E1001', @StartDate='2012-07-26 07:00', @EndDate='2012-07-26 22:00'

Go


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Rock_Monu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 8/9/2012 [Member] Starter | Points: 25

Up
0
Down

select empid,empname,empaddress from tablename1
inner join tablename2
on
tablename1.empid=tablename2.empid



sriram

Rock_Monu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mrashish77 on: 8/20/2012 [Member] Starter | Points: 25

Up
0
Down
Select E.Empname,EA.Empattendence From tbl_emp E With(Nolock) Join tbl_emp_attendence EA With(Nolock)
On (E.Empid = EA.Empid)
Where E.Empid = ISNULL(@EmpID,E.Empid ) -- to select data for all employees
And EA.Empattendence Between @StartDate And @EndDate

Rock_Monu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: San.Pblr.Gct on: 8/20/2012 [Member] Starter | Points: 25

Up
0
Down
declare @startdate datetime
declare @enddate datetime
declare @empid int
set @startdate=something
set @empid=something
set @enddate=something

select empname,empattendence from tbl_emp emp
inner join tbl_emp_attendence empa on emp.empid=empa.empid
where empattendance between @startdate and @enddate
and empid =@empid

Rock_Monu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response