Click here to Skip to main content
15,899,475 members
Home / Discussions / Database
   

Database

 
Questionhow to create a query by using store procedure in SQL Server 2000 ? Pin
Golden Jing15-Feb-09 15:10
Golden Jing15-Feb-09 15:10 
AnswerRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
_Maxxx_15-Feb-09 16:34
professional_Maxxx_15-Feb-09 16:34 
GeneralRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
Golden Jing15-Feb-09 17:21
Golden Jing15-Feb-09 17:21 
GeneralRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
_Maxxx_15-Feb-09 18:31
professional_Maxxx_15-Feb-09 18:31 
GeneralRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
Golden Jing15-Feb-09 20:45
Golden Jing15-Feb-09 20:45 
GeneralRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
_Maxxx_16-Feb-09 12:50
professional_Maxxx_16-Feb-09 12:50 
GeneralRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
Golden Jing17-Feb-09 20:58
Golden Jing17-Feb-09 20:58 
GeneralRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
_Maxxx_17-Feb-09 21:53
professional_Maxxx_17-Feb-09 21:53 
I wasn't sure whether there was a date and a time field - or a single datetime field in your DB - I had assumed a single datetime field which I called dt.

FLOOR(CAST(Dt AS Float)) gives you just the Date portion of your DateTime field. if you have separate Date and Time fields you can replace
FLOOR(CAST(Dt AS Float))
by
dt

if your date field is called dt

The idea of the query is that it selects all records for all employees where there is an 'In' record ... so this
WHERE     (status = 'I') AND (NOT EXISTS
                          (SELECT     1 AS Expr1
                            FROM          clock AS c1
                            WHERE      (EmpId = c.EmpId) AND (status = 'I') AND (Dt < c.Dt) AND (FLOOR(CAST(Dt AS Float)) = FLOOR(CAST(c.Dt AS Float)))))


selects where is is an In record (status = 'I') and

There are no records (not exists) for the same employee (empId = c.EmpId) that is an 'In' record (status = 'I') where the datetime is earlier (dt < c/DT) and the Date is the same.

You could rewrite this if you have a date column called dt and a time column called tm as

(EmpId = c.EmpId) AND (status = 'I') AND (tm < c.tm) AND (dt = c.Dt )


which makes it easier to read!
You can see then that this logic is just checking that tehre are no In records, for this employee, for the same date, that are earlier in the day - or, in other words, only include records that are the first In record for the day.

Having got this record, the first Out column, second In and Out columns are all based upon this record

I'm not on the computer where I created the database to test this right now - when I am, if I have time, I will change it to look like your DB and chaneg teh SQL for you - but if you follow my advice above, you should get there!@

good luck

___________________________________________
.\\axxx
(That's an 'M')

GeneralRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
Golden Jing17-Feb-09 22:27
Golden Jing17-Feb-09 22:27 
AnswerRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
Wendelius15-Feb-09 18:09
mentorWendelius15-Feb-09 18:09 
GeneralRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
Golden Jing15-Feb-09 20:35
Golden Jing15-Feb-09 20:35 
GeneralRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
Wendelius15-Feb-09 21:23
mentorWendelius15-Feb-09 21:23 
GeneralRe: how to create a query by using store procedure in SQL Server 2000 ? Pin
Golden Jing15-Feb-09 22:41
Golden Jing15-Feb-09 22:41 
QuestionAb Inito conundrums.... Pin
PoisonCreed14-Feb-09 15:04
PoisonCreed14-Feb-09 15:04 
AnswerRe: Ab Inito conundrums.... Pin
Ashfield15-Feb-09 8:16
Ashfield15-Feb-09 8:16 
GeneralRe: Ab Inito conundrums.... Pin
PoisonCreed15-Feb-09 12:48
PoisonCreed15-Feb-09 12:48 
GeneralRe: Ab Inito conundrums.... Pin
Ashfield15-Feb-09 20:57
Ashfield15-Feb-09 20:57 
QuestionSQL SERVER 2005 INSTALLATION Pin
Member 465028714-Feb-09 5:16
Member 465028714-Feb-09 5:16 
AnswerRe: SQL SERVER 2005 INSTALLATION Pin
Wendelius14-Feb-09 6:29
mentorWendelius14-Feb-09 6:29 
GeneralRe: SQL SERVER 2005 INSTALLATION Pin
Member 465028714-Feb-09 8:00
Member 465028714-Feb-09 8:00 
GeneralRe: SQL SERVER 2005 INSTALLATION Pin
Wendelius14-Feb-09 9:12
mentorWendelius14-Feb-09 9:12 
Questioncan't find AdventureWorks.dbml Pin
TerRO_GirL14-Feb-09 1:25
TerRO_GirL14-Feb-09 1:25 
AnswerRe: can't find AdventureWorks.dbml Pin
Wendelius14-Feb-09 1:36
mentorWendelius14-Feb-09 1:36 
GeneralRe: can't find AdventureWorks.dbml Pin
TerRO_GirL14-Feb-09 2:08
TerRO_GirL14-Feb-09 2:08 
GeneralRe: can't find AdventureWorks.dbml Pin
Wendelius14-Feb-09 2:15
mentorWendelius14-Feb-09 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.