navigator703
MIS
Hey Folks-
I have a query here where I am looking for the first time a property has gone active. The twist is that I only want properties where they have gone active in last 18 months [July 2006]. I am have been looking for a while in other posts for another topic like mine, but nothing is quite what I am looking for.
[ul]
[li]sample data[/li][/ul]
OR00119 Snellvile Shop OR-Snellvile 1392 BR 10/23/2006
OR00365 Market Shop OR-Beltsville 1020 BR 08/23/2007
I am still coming up with older data than my criteria is filtering for. Here is some of the results:
[ul]
[li]sample bad data[/li][/ul]
OR00119 Snellvile Shop OR-Snellvile 1392 BR 10/23/2006
OR00365 Market Shop OR-Beltsville 1020 BR 08/23/2007
WA00119 Downtown Shop WA-Seattle 302 BR 09/20/2004
If you have any suggestions, let me know!
~ a journey of a thousand miles must begin with a single step ~
I have a query here where I am looking for the first time a property has gone active. The twist is that I only want properties where they have gone active in last 18 months [July 2006]. I am have been looking for a while in other posts for another topic like mine, but nothing is quite what I am looking for.
Code:
SELECT P.PRPTY_ID, P.PRPTY_NM, P.DIST_CD, P.LOC_CD, P.PRPTY_TY_CD, MIN (ST1.ACTIVE_DATE) AS ACTIVE_DT
FROM T_PRPTY P INNER JOIN (SELECT S1.PRPTY_ID, S1.STAT_TY_CD AS STAT_TY_CD, MIN (S1.STAT_CHNG_DT) AS ACTIVE_DATE
FROM T_STAT S1
WHERE (DATEDIFF(mm,S1.STAT_CHNG_DT, GETDATE()) <= 18) AND S1.STAT_TY_CD = 'ACTIVE'
GROUP BY S1.PRPTY_ID, S1.STAT_TY_CD, S1.STAT_CHNG_DT) AS ST1 ON P.PRPTY_ID = ST1.PRPTY_ID
GROUP BY P.PRPTY_ID, P.DIST_CD, P.PRPTY_NM, P.LOC_CD, P.PRPTY_TY_CD
ORDER BY P.PRPTY_ID
[ul]
[li]sample data[/li][/ul]
OR00119 Snellvile Shop OR-Snellvile 1392 BR 10/23/2006
OR00365 Market Shop OR-Beltsville 1020 BR 08/23/2007
I am still coming up with older data than my criteria is filtering for. Here is some of the results:
[ul]
[li]sample bad data[/li][/ul]
OR00119 Snellvile Shop OR-Snellvile 1392 BR 10/23/2006
OR00365 Market Shop OR-Beltsville 1020 BR 08/23/2007
WA00119 Downtown Shop WA-Seattle 302 BR 09/20/2004
If you have any suggestions, let me know!
~ a journey of a thousand miles must begin with a single step ~