|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 3:41 AM
Points: 140,
Visits: 474
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, September 10, 2009 2:31 AM
Points: 4,
Visits: 22
|
|
Hi Divya, it gud..
you just can minimize the query length a little by removing the highlighted text...
SELECT *, (SELECT CASE WHEN (SUM(CASE WHEN B.DEDate =1 THEN 1 ELSE 0 END AS isawk from PersonRecord B CROSS JOIN PersonRecord C WHERE B.PersonID=A.PersonID AND C.PersonID=A.PersonID AND B.VERSION<>C.VERSION AND B.VERSION<C.VERSION) AS [Is ImProper] from PersonRecord A
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 1:35 AM
Points: 4,787,
Visits: 1,336
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, September 10, 2009 2:31 AM
Points: 4,
Visits: 22
|
|
can anyone perform this task with two tables only....
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 3:41 AM
Points: 140,
Visits: 474
|
|
Yes it will optimize the performance of the query
--Divya
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 3:41 AM
Points: 140,
Visits: 474
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 3:41 AM
Points: 140,
Visits: 474
|
|
Performing task with two tables?? Could you please clarify your query??
--Divya
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 2:52 PM
Points: 1,322,
Visits: 1,071
|
|
Why use the cross join?
SELECT * FROM PersonRecord A INNER JOIN PersonRecord B ON A.PersonID = B.PersonID AND A.VersionID = B.VersionID - 1 WHERE B.DEDate > A.DEDate
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, September 10, 2009 2:31 AM
Points: 4,
Visits: 22
|
|
| yes the task could have been done this way but she wants all the records to be called improper if any of the date is not proper
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, February 04, 2013 10:20 AM
Points: 165,
Visits: 130
|
|
Nice ideas - I work in the insurance industry and use this often to look for out-of-sequence endorsements and transactions. Here's another way to acheive it, without a join.
select personid, version, dedate, row_number() over (partition by personid order by version) as VersionOrder, row_number() over (partition by personid order by dedate) as DeOrder, case when row_number() over (partition by personid order by version) - row_number() over (partition by personid order by dedate) <> 0 then '1' else '0' end as IsImproper from personrecord order by personid, version
Only catch here (and for others) is that both fileds you are comparing over a given personid must be unique...
|
|
|
|