Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:05:20+00:00 2026-06-15T10:05:20+00:00

Im using Ms SQL database, My table looks, SrNo Emp_ID Date Time ———————————— 1

  • 0

Im using Ms SQL database,
My table looks,

SrNo  Emp_ID   Date          Time 
------------------------------------
  1    25     03-Sep-12    9:35:35 AM  
  2    25     03-Sep-12   10:31:32 AM 
  3    25     03-Sep-12   10:34:13 AM 
  4    25     03-Sep-12   11:05:08 AM 
  5    25     03-Sep-12   11:08:39 AM 
  6    25     04-Sep-12   09.05.40 AM     

The expected output is

 SrNo  Emp_ID   Date          Time     Type 
---------------------------------------------
  1    25     03-Sep-12    9:35:35 AM  IN
  2    25     03-Sep-12   10:31:32 AM  OUT
  3    25     03-Sep-12   10:34:13 AM  IN
  4    25     03-Sep-12   11:05:08 AM  OUT
  5    25     03-Sep-12   11:08:39 AM  IN
  6    25     04-Sep-12   09.05.40 AM  IN

For an employee, type “in” and “out” has to be added simultaneously for particular date. For the next date or next /same employee, type has to start with “IN”. Can any 1 help me in writing the sql query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:05:21+00:00Added an answer on June 15, 2026 at 10:05 am

    You can achieve this using an additional column

    ROW_NUMBER() OVER (PARTITION BY Emp_ID, Date ORDER BY Time) AS RN

    then checking modulus 2 on it, if remainder is 1, it’s an IN, if it’s 0 it’s an OUT, based on your requirements.

    More specifically

    CASE WHEN 
      ROW_NUMBER() OVER (PARTITION BY Emp_ID, Date ORDER BY Time) % 2 = 1 
         THEN 'IN' 
         ELSE 'OUT' 
      END AS [Type]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQL Server 2008. I have a database table that looks like this
I am using SQL Server CE database and C# language. I have a table
I'm using a standard SQL database and I'm trying to figure out whether or
I have Database table and I am using SQL Server 2008. The table contins
I need to select rows from database table using filtering by xml-type column. table
I'm trying to create a table in a database using SQL. The data is
I am using Sql database and I have indexed some tables. In some tables
I'm using SQL Express 2008 edition. I've planned my database tables/relationships on a piece
iv created a database with some tables and populated them using SQL server 2008,
Using SQL Server 2005 Database1 Table1 ID Date Status 001 23-02-2009 Worked 001 24-02-2009

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.