adspace


I have a table Events

Events containing

cardno,time,id,name--each id has a cardno



my requirement is every day each employee swipe the card
several times

i want to calculate first and last time of each card

the output should be

name 1 2
6 7
in out in out
holiday holiday
xxx 09:30 06:30 09:40 06:45
where 1,2...... are dates for example january 1,2, etc. 6
and 7 are saturday and sunday

how it is posssible

Answer Posted / Atul Chaudhary

To achieve this in SQL Server, you can use the ROW_NUMBER() function to number each row for each cardno and day, and then select the rows with the minimum and maximum time for each cardno. Here's an example query:
SELECT
id,
cardno,
MIN(time) AS 'in',
MAX(time) AS 'out',
DATEPART(dd, time) AS 'day',
DATENAME(dw, time) AS 'weekday'
FROM Events
WHERE time IS NOT NULL
GROUP BY id, cardno, weekday
ORDER BY cardno, day

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the properties of the transaction?

1074


How to remove duplicate rows from table except one?

1090


How can I check that whether automatic statistic update is enabled or not?

1113


How can we solve concurrency problems?

1123


Can one drop a column from a table?

1091


What are the pros and cons of putting a scalar function in a queries select list or in the where clause?

1300


Can we make the the chages By Using the Sql if u know any function or process please inform me Actuall result: BRK1 Break 1 Part 1 00:01:00:00 60 BRK1 Break 1 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 BRK2 Break 2 Part 2 00:01:00:00 60 BRK2 Break 2 Part 3 00:01:00:00 60 BRK3 Break 3 Part 1 00:01:00:00 60 BRK3 Break 3 Part 2 00:01:00:00 60 Desired O/P: BRK1 Break 1 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 Part 3 00:01:00:00 60

2296


Why should you use or avoid select * statements?

1111


If any stored procedure is encrypted, then can we see its definition in activity monitor?

1072


What is the difference between upgrade and migration in sql server?

1185


Explain “row_number()” in sql server with an example?

1080


What is an indexed view?

1023


do you know how to configure db2 side of the application? : Sql server database administration

1125


what is the difference between openrowset and openquery?

1197


What is normalization and what are the advantages of it?

1057