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

  • Home
  • SEARCH
  • 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 6200035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:17:43+00:00 2026-05-24T04:17:43+00:00

;with cte as ( select FingerId, [Date], LogTime, row_number() over(partition by FingerId order by

  • 0
;with cte as
( 
  select FingerId, [Date],
         LogTime,
         row_number() over(partition by FingerId order by LogTime) as rn
  from InOut 
)
select C3.EmployeeName,C1.FingerId,
       C1.LogTime as InTime,
       C2.LogTime as OutTime,
       C2.[Date]
from cte as C1
  left outer join cte as C2
    on C1.FingerId = C2.FingerId and
       C1.rn + 1 = C2.rn INNER JOIN
           EmployeeMaster as C3 ON C3.Fingerid = C2.Fingerid
where C1.rn % 2 = 1 and  C3.EmployeeName = 'xyz' and C1.[Date] between '2011-07-21' and '2011-07-29' order by C2.[Date]

select * From Inout order by LogTime asc 

I am having INOUT Table It have 5 record and 3 record is of 2011-07-2011

InOuT Table:

AutoId     FingerId      LogTime            Date
1            22          11:18:48 AM       2011-07-29
2            22          11:19:54 AM       2011-07-29
3            22          11:20:50 AM       2011-07-21
4            22          11:21:54 AM       2011-07-21
5            22          11:21:59 AM       2011-07-21

I am getting this output by this above query

EmployeeName  FingerId   InTime         OutTime        Date

xyz             22        11:20:50 AM    11:21:54 AM   2011-07-21 
xyz             22        11:18:48 AM    11:19:54 AM   2011-07-29

I Want this type of OutPut:-

EmployeeName  FingerId   InTime         OutTime        Date

xyz             22        11:20:50 AM    11:21:54 AM   2011-07-21
xyz             22        11:21:59 AM    ----          2011-07-21  
xyz             22        11:18:48 AM    11:19:54 AM   2011-07-29

Here 2nd row is having InTime and i want outtime should display “—” dash.But i m not getting with this query. Query is correct but need to do modify for this.

  • 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-05-24T04:17:43+00:00Added an answer on May 24, 2026 at 4:17 am

    I’ve made some modifications to your query which I’m posting now with the changes highlighted in bold:

    ;WITH cte AS
    ( 
      SELECT FingerId, [Date],
             LogTime,
             ROW_NUMBER() OVER(PARTITION BY FingerId ORDER BY LogTime) AS rn
      FROM InOut 
    )
    SELECT C3.EmployeeName,C1.FingerId,
           C1.LogTime AS InTime,
           C2.LogTime AS OutTime,
           COALESCE(C2.[Date], C1.[Date]) AS Date
    FROM cte AS C1
      LEFT OUTER JOIN cte AS C2 ON C1.FingerId = C2.FingerId AND C1.rn + 1 = C2.rn
      INNER JOIN EmployeeMaster AS C3 ON C3.Fingerid = C1.Fingerid
    WHERE C1.rn % 2 = 1
      AND C3.EmployeeName = 'xyz'
      AND C1.[Date] BETWEEN '2011-07-21' AND '2011-07-29'
    ORDER BY C1.[Date]
    

    Originally I was thinking about changing C1.[Date] in the SELECT clause to C2.[Date], but then I wasn’t sure it would be quite adequate a replacement in case the two dates were different. You can see for yourself which option is better, if any.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

WITH emp_CTE AS ( SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS IdentityId, * FROM
I have a query as follows: WITH CTE AS ( SELECT MIN(att.Date) [minDate] FROM
I have these Queries: With CTE(comno) as (select distinct comno=ErpEnterpriseId from company) select id=Row_number()
My stored proc looks like: WITH MYCTE(...) AS ( .. ) SELECT cte.* FROM
with cte as ( select rowid from batchinfo where datapath like '%thc%' ) select
with cte as ( select rowid from batchinfo where datapath like '%thc%' ) select
Is there any performance gain using a CTE over a derived table?
I have the following query: WITH cte AS ( SELECT windowId, frameIndx, elemIndx, comment,
I want to optimize this query WITH CTE AS ( SELECT KladrItemName _KladrItemName ,
I am executing the following statement: ;WITH cte AS ( SELECT 1 as rn,

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.