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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 If the previous record is within 24 hours

Author  Topic 

mlevier
Starting Member

33 Posts

Posted - 2007-10-02 : 15:04:09
I am trying to figure out how to look at the previous record with the same ani is within 24 hours of the current record. If it is within 24 hours it gets a 1 in the callback field. If it is > than 24 hours with the same ani then it gets a 0 in the callback field.

If you look below I created two temp tables to try to get this to work. I'm am stuck and don't know where else to go. Any help would be great.

create table #CallBack
( CallBack nvarchar(50),
datetime datetime,
Ani varchar(50),
RowNumber bigint
)
------------------------------------------
Insert into #Repeat
(#Repeat.CallBack, #Repeat.datetime, #Repeat.Ani, #Repeat.RowNumber)
select Calls.CallBack, Calls.datetime, Calls.Ani, row_number()over (order by ani, datetime desc) as rownumber
from Calls
where Calls.DateTime >= CAST(CONVERT(varchar(10), GETDATE() -3, 101) AS smalldatetime)
order by Ani, datetime desc
------------------------------------------
create table #Repeat02
( CallBack nvarchar(50),
datetime datetime,
Ani varchar(50),
RowNumber bigint
)
-------------------------------------------
Insert into #Repeat02
(#Repeat02.CallBack, #Repeat02.datetime, #Repeat02.Ani, #Repeat02.RowNumber)
select #Repeat.CallBack, #Repeat.datetime, #Repeat.Ani, #Repeat.RowNumber
from #Repeat
order by Ani, datetime desc

Zoroaster
Aged Yak Warrior

702 Posts

Posted - 2007-10-02 : 15:28:14
Ah.. telecom:

I can't really make sense of what you have posted above, what is the table you are querying and what table are you attempting to update with the 0 and 1 for callback field? It would help if you just provide the table structure(s) for the tables involved instead of the temp tables.





Future guru in the making.
Go to Top of Page
   

- Advertisement -