dkilby
asked on
Help With MS SQL Query
I need a query in MS SQL that shows me the count of records that meet the below criteria.
4 fields - CustomerName, Direction, Disposition, TimeStamp
I need all records where Direction = Outbound, Disposition = Voicemail, and there is a record after the timestamp from the first critera with the same customer name, direction = inbound.
Is this possible and if so how ?
4 fields - CustomerName, Direction, Disposition, TimeStamp
I need all records where Direction = Outbound, Disposition = Voicemail, and there is a record after the timestamp from the first critera with the same customer name, direction = inbound.
Is this possible and if so how ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try
select *
from tab1
wheres CustomerName+ltrim(cast(TimeStamp as varchar)) in(select CustomerName+ltrim(cast(min(TimeStamp) as varchar)) from tab1 a
where CustomerName+ltrim(cast(TimeStamp as varchar)) > (select CustomerName+ltrim(cast(max(TimeStamp) as varchar))
from tab1
where Direction = 'Outbound' and Disposition = 'Voicemail'
group by CustomerName)
and direction = 'Inbound'
group by CustomerName)
go
and if so how ? .... by using a SQL query e.g.
from sometable
where Direction = Outbound
and Disposition = Voicemail
You should provide sample data and the expected result to make this bit clear:
>>"and there is a record after the timestamp from the first criteria with the same customer name, direction = inbound."
Is the "first criteria" Direction = Outbound?