Hi,
I have a query as part of a stored procedure and the results are correct. I do however need to add code to compare the results to the results of the same query when it last ran e.g. 2 days ago. I then need any new records that was not on the results from 2 days ago to appear on top (first) in the results.
Any help will be appreciated how to do this. Thank you
Query:
SELECT *
FROM
(
SELECT rt.sPortfolio, CAST(rt.iRuleId AS VARCHAR(15)) AS iRuleId, sDescription, sComment, rt.sPortfolio AS BlankRow
FROM thinktank..ruletests AS rt
INNER JOIN thinktank..rules AS r
ON r.id = rt.iruleid
AND dttest > getdate()-1
AND iresult <> 4
AND ichecktype = 3
AND r.iCategory = 0
AND sRuleSet <> 'NOTIFY'
INNER JOIN thinktank..GroupPortfolios AS gp
ON rt.sPortfolio = gp.sPortfolioId
AND sGroupID = 'EC'
LEFT OUTER JOIN thinktank..RuleUCs AS ruc
ON r.id = ruc.iruleid
AND ruc.icategory = '636'
WHERE ISNULL(ruc.sValue,'N') <> 'Y'
UNION
SELECT '', '','','', rt.sPortfolio AS BlankRow
FROM thinktank..ruletests AS rt
INNER JOIN thinktank..rules AS r
ON r.id = rt.iruleid
AND dttest > getdate()-1
AND iresult <> 4
AND ichecktype = 3
AND r.iCategory = 0
AND sRuleSet <> 'NOTIFY'
INNER JOIN thinktank..GroupPortfolios AS gp
ON rt.sPortfolio = gp.sPortfolioId
AND sGroupID = 'EC'
LEFT OUTER JOIN thinktank..RuleUCs AS ruc
ON r.id = ruc.iruleid
AND ruc.icategory = '636'
WHERE ISNULL(ruc.sValue,'N') <> 'Y'
GROUP BY rt.sPortfolio
) AS tbl
ORDER BY BlankRow ASC, sPortfolio DESC, iRuleId ASC