Home Forums SQL Server 2008 SQL Server 2008 - General Is there a way to do this with lag in 2012 or without Temp tables in 2008? RE: Is there a way to do this with lag in 2012 or without Temp tables in 2008?

  • Thank you for your help...going over your correction, I realized that i could make the problem smaller by putting an index over carrier and benefit start date then attack each carrier separately, so i went through three iterations to get to where i think it needs to be

    select memberid, carrier, planname, plantype,tiername, premium,benefitstartdate,

    case when benefitenddate = '20991231' then displayenddate else benefitenddate end newenddate, displayenddate

    from ees

    where '20131231'>=[BenefitStartDate]

    and not (carrier in ( 'Elect', 'Waive'))

    order by 2

    --but this left 2014 in the end date, so i tried to nest the case statement

    select memberid, carrier, planname, plantype, tiername, premium, benefitstartdate,

    case when benefitenddate = '20991231' then

    case when year(displayenddate)='2014' then '20131231' end else benefitenddate end, displayenddate

    from ees

    where '20131231'>=[BenefitStartDate]

    and not (carrier in ( 'Elect', 'Waive'))

    order by 2

    but that left nulls in the end date, so i switched the 'stuffing' for the case statement to

    select memberid , carrier ,planname, plantype, tiername, premium, benefitstartdate,

    case when benefitenddate = '20991231' then '20131231' else benefitenddate end, displayenddate

    from ees

    where '20131231'>=[BenefitStartDate]

    and not (carrier in ( 'Elect', 'Waive'))

    order by 2

    and that left the result in the state i needed it, substituting 12/31/2013 where there was 12/31/2099 or the real benefit end date.

    Thank you for the push.