Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Calculating date differences

Author  Topic 

Emile
Starting Member

5 Posts

Posted - 2013-03-20 : 04:57:32
Hello?
In my arLogDet table I'm trying to calculate the next date from the next SeqNo so that i can find the difference between the ActionEndDate
and ActionDueDate, I calculate the ActionDueDate from when the action started adding how many days the action will take then to see if it was completed in the appropiate time i check the date with SeqNo + 1 to get the next action date so that i can see if the action was passed to the next user before the ActionDueDate, this sql select statement will populate a tempory table in a proc.The date I want to get the results for is in arLogDet,the others tables are so i can get my UserId, DaysperAction.Im really struggling to figure this out???

select (select Date from arLogDet where SeqNo = SeqNo+1) as ActionEndDate,
U.UserId,
A.DaysPerAction,
D.SeqNo,
D.Date,
D.DocId,
D.RequestId,
DateAdd(Day, A.DaysPerAction, D.Date) as ActionDueDate

from awUser U
join arLogDet D
on U.UserId = D.UserId
join arLogHdr H
on D.RequestId = H.RequestId
join arAction A
on H.ActionId = A.ActionId
where U.UserId = 159
and H.RequestId = 55

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-20 : 05:23:45
--May be this
select (select Date from arLogDet where SeqNo = D.SeqNo+1) as ActionEndDate,
U.UserId,
A.DaysPerAction,
D.SeqNo,
D.Date,
D.DocId,
D.RequestId,
DateAdd(Day, A.DaysPerAction, D.Date) as ActionDueDate

from awUser U
join arLogDet D
on U.UserId = D.UserId
join arLogHdr H
on D.RequestId = H.RequestId
join arAction A
on H.ActionId = A.ActionId
where U.UserId = 159
and H.RequestId = 55

If not, post the sample data of sample data of each table and also explain the logic what you want... show us the expected output for your sample data.. Hence you can get quick responses

--
Chandu
Go to Top of Page

Emile
Starting Member

5 Posts

Posted - 2013-03-20 : 07:01:20
thank you very much, that helps alot with this step, gonna try apply it, will be back soon
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-20 : 08:53:29
quote:
Originally posted by Emile

thank you very much, that helps alot with this step, gonna try apply it, will be back soon

Got the result

--
Chandu
Go to Top of Page
   

- Advertisement -