Home Forums SQL Server 7,2000 T-SQL How to get ssns that occures in less than 12 month gap RE: How to get ssns that occures in less than 12 month gap

  • Keeping my previous question open , here's one solution to ur problem.

    I came up with this quickly (so there could be better ways of doing it)..

    And again if u're using this for a large dataset the queries can be optimised..

    -- Scenario 1

    select SSN

    from #mytemp

    where datediff (m,cast(period + '-01' as datetime),getdate()) <=12

    group by SSN

    having COUNT(SSN) >1

    -- Scenario 2

    select SSN,planID

    from #mytemp

    where datediff (m,cast(period + '-01' as datetime),getdate()) <=12

    group by SSN,planID

    having COUNT(SSN) >1

    "The price of anything is the amount of life you exchange for it" - Henry David Thoreau