February 17, 2014 at 6:17 pm
create table dbo.abc(id varchar(10), version int, stat varchar(10),typo varchar(10),enterdate datetime)
insert into abc(id,version,stat,typo,enterdate)
select 100,10,'live','yes',getdate()
union
select 100,10,'live','yes',getdate()-1
union
select 100,10,'live','no',getdate()-2
union
select 100,10,'nonlive','yes',getdate()
union
select 101,9,'live','no',getdate()
union
select 101,8,'live','yes',getdate()-2
union
select 101,11,'nonlive','yes',getdate()
i want to get an output on below conditions:
1. only live data
2. find the current day id and compare with it recent previous live date.
a. if the currunt and previous stat is different then show data.
b. if current date and immediate previous live stat is same (eg. both are yes or both are no) ten do not show ay data for the that id.
this query will be run daily to check currunt day data with recent previous data.
February 17, 2014 at 6:35 pm
try this and see if it works
SELECT *
FROM abc a1
INNER JOIN abc a2
ON a1.id = a2.id
AND a1.enterdate = a2.enterdate+1
AND a1.stat = a2.stat
WHERE a1.stat = 'Live'
AND a1.typo <> a2.typo;
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
February 18, 2014 at 3:04 pm
Post withdrawn. I thought this was going to turn out to be a massive double triangular join but a second look-see says it probably won't.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply