What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 15480 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > SQL Server > Interview Question : Select List Of those Employee who comes late Office after Office Timing ...
Anu.Malik

Interview Question : Select List Of those Employee who comes late Office after Office Timing

 Code Snippet posted by: Anu.Malik | Posted on: 7/6/2012 | Category: SQL Server Codes | Views: 806 | Status: [Member] | Points: 40 | Alert Moderator   


CREATE TABLE EMPMaster(
[EMP_Name] [varchar](50) NULL,
[InTime] [datetime] NULL
)

Insert INTO EMPMaster Values('AA','2012-07-06 09:33:02.933')
Insert INTO EMPMaster Values('BB','2012-07-06 08:45:02.933')
Insert INTO EMPMaster Values('CC','2012-07-06 10:45:02.933')
Insert INTO EMPMaster Values('DD','2012-07-06 09:33:02.933')
Insert INTO EMPMaster Values('EE','2012-07-06 08:59:02.933')
Insert INTO EMPMaster Values('FF','2012-07-06 10:33:02.933')

Declare @OfficeTime Varchar(10)
Set @OfficeTime='09:00AM'

SELECT * FROM EMPMaster WHERE CONVERT(VARCHAR,GETDATE(),101)=CONVERT(VARCHAR,InTime,101) AND
RIGHT('0'+LTRIM(RIGHT(CONVERT(varchar,InTime,100),8)),7) > @OfficeTime

Thanks & Regards ,
Anu Malik
Found interesting? Add this to:


 Responses

Jasminej
Posted by: Jasminej | Posted on: 7/6/2012 | Level: Starter | Status: [Member] | Points: 10 | Alert Moderator 

You can also simple use like...
Declare @OfficeTime Varchar(10)


Set @OfficeTime='09:00AM'

Select * from EMPMaster
Where [InTime] > Cast(CONVERT(Varchar(10), GetDate(),121) + ' ' + @OfficeTime as Datetime)


Anu.Malik
Posted by: Anu.Malik | Posted on: 7/6/2012 | Level: Starter | Status: [Member] | Points: 10 | Alert Moderator 

Yes Nice

Thanks & Regards ,
Anu Malik

>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 2:27:17 PM