sql server - Getting the all record from table using declared veriables -
i have written query getting records table query give me 1 record kindly help me how record table or giving condition. shall thankfull lovely kind of deed
declare @shifttimeinminute int declare @shifttimeoutminute int declare @dutyinminute int declare @dutyoutminute int declare @totaldutyminute int declare @totaltimeminute int declare @shiftstarttime datetime declare @shiftendtime datetime declare @intime datetime declare @outtime datetime declare @dateinhour varchar(100) declare @dateouthour varchar(100) declare @position varchar(100) set @shiftstarttime=(select distinct tblhrshifttime.shiftstarttime tblhrshifttime inner bring together tblhremployee emp on emp.shifttimingid = tblhrshifttime.shifttimeid emp.employeeid in (select distinct employeeid tblhrattendancelog tblhrattendancelog.branchid = '5' , convert(date, datetime) = '2014-03-25')) set @shiftendtime=(select distinct tblhrshifttime.shiftendtime tblhrshifttime inner bring together tblhremployee emp on emp.shifttimingid = tblhrshifttime.shifttimeid emp.employeeid in (select distinct employeeid tblhrattendancelog tblhrattendancelog.branchid = '5' , convert(date, datetime) = '2014-03-25')) set @shifttimeinminute=datepart(hour, convert(char(5), @shiftstarttime, 108)) * 60 + datepart(minute, convert(char(5), @shiftstarttime, 108)) set @shifttimeoutminute= datepart(hour, convert(char(5), @shiftendtime, 108)) * 60 + datepart(minute, convert(char(5), @shiftendtime, 108)) set @totaldutyminute=@shifttimeoutminute - @shifttimeinminute select @position = tblhrpositions.positiontitle, @intime = case when tblhrshifttime.shiftstarttime < tblhrshifttime.shiftendtime (select min(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25') else (select max(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25') end, @outtime = case when tblhrshifttime.shiftstarttime > tblhrshifttime.shiftendtime (select min(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25') else (select max(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25') end, @dateinhour = case when tblhrshifttime.shiftstarttime < tblhrshifttime.shiftendtime convert(char(5), (select min(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108) when tblhrshifttime.shiftstarttime > tblhrshifttime.shiftendtime convert(char(5), (select max(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108) end, @dateouthour = case when tblhrshifttime.shiftstarttime > tblhrshifttime.shiftendtime convert(char(5), (select min(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108) when tblhrshifttime.shiftstarttime < tblhrshifttime.shiftendtime convert(char(5), (select max(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108) end, @dutyinminute = case when @shiftstarttime < @shiftendtime datepart(hour, convert(char(5), (select min(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108)) * 60 + datepart(minute, convert(char(5), (select min(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108)) when @shiftstarttime > @shiftendtime datepart(hour, convert(char(5), (select max(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108)) * 60 + datepart(minute, convert(char(5), (select max(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108)) end, @dutyoutminute = case when @shiftstarttime > @shiftendtime datepart(hour, convert(char(5), (select min(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108)) * 60 + datepart(minute, convert(char(5), (select min(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108)) when @shiftstarttime < @shiftendtime datepart(hour, convert(char(5), (select max(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108)) * 60 + datepart(minute, convert(char(5), (select max(datetime) tblhrattendancelog tblhremployee.employeeid = tblhrattendancelog.employeeid , convert(date, datetime) = '2014-03-25'), 108)) end tblhrattendancelog inner bring together tblhremployee on tblhrattendancelog.employeeid = tblhremployee.employeeid inner bring together tbldrcontacts on tblhremployee.contactid = tbldrcontacts.contactid inner bring together tblhremployeepositions on tblhremployee.employeeid = tblhremployeepositions.employeeid inner bring together tblhrshifttime on tblhremployee.shifttimingid = tblhrshifttime.shifttimeid inner bring together tblhrpositions on tblhremployeepositions.positionid = tblhrpositions.positionid inner bring together tblsabranchdepartments section on department.branchdepartmentid = tblhremployeepositions.branchdepartmentid ( tblhrattendancelog.branchid = 5 , department.departmentid = 16 ) , ( convert(date, datetime) = '2014-03-25' , tblhremployeepositions.iscoreposition = 1 , tblhrattendancelog.employeeid in (select distinct employeeid tblhrattendancelog tblhrattendancelog.branchid = '5' , convert(date, datetime) = '2014-03-25') ) select @shifttimeinminute shiftinminute, @shifttimeoutminute shiftoutminute, @totaldutyminute totaldutyminute, @intime intime, @outtime outtime, @dateinhour dateinhour, @dateouthour dateouthour, @position
sql-server
No comments:
Post a Comment