Help with Temp Table with Case Statement

  • I'm trying to build a temp table to run my Start Date and End Date Parameters from the current fiscal year.

    I'm getting an error when I try to run this temp table. I'm not sure exactly what i'm doing wrong?

    Msg 213, Level 16, State 1, Line 4

    Column name or number of supplied values does not match table definition.

    Create Table #TempLocation

    (FyStart Date, FyEnd Date)

    Insert Into #TempLocation

    Values

    ( Case WHEN GetDate() Between '07/01/08' and '06/30/09' Then '07/01/08'

    WHEN GetDate() Between '07/01/09' and '06/30/10' Then '07/01/09'

    WHEN GetDate() Between '07/01/10' and '06/30/11' Then '07/01/10'

    WHEN GetDate() Between '07/01/11' and '06/30/12' Then '07/01/11'

    WHEN GetDate() Between '07/01/12' and '06/30/13' Then '07/01/12'

    WHEN GetDate() Between '07/01/13' and '06/30/14' Then '07/01/13'

    WHEN GetDate() Between '07/01/14' and '06/30/15' Then '07/01/14'

    WHEN GetDate() Between '07/01/15' and '06/30/16' Then '07/01/15'

    WHEN GetDate() Between '07/01/16' and '06/30/17' Then '07/01/16'

    WHEN GetDate() Between '07/01/17' and '06/30/18' Then '07/01/18'

    WHEN GetDate() Between '07/01/18' and '06/30/19' Then '07/01/19'

    WHEN GetDate() Between '07/01/19' and '06/30/20' Then '07/01/20'

    End),

    (Case WHEN GetDate() Between '07/01/08' and '06/30/09' Then '07/01/08'

    WHEN GetDate() Between '07/01/09' and '06/30/10' Then '06/30/10'

    WHEN GetDate() Between '07/01/10' and '06/30/11' Then '06/30/11'

    WHEN GetDate() Between '07/01/11' and '06/30/12' Then '06/30/12'

    WHEN GetDate() Between '07/01/12' and '06/30/13' Then '06/30/13'

    WHEN GetDate() Between '07/01/13' and '06/30/14' Then '06/30/14'

    WHEN GetDate() Between '07/01/14' and '06/30/15' Then '06/30/15'

    WHEN GetDate() Between '07/01/15' and '06/30/16' Then '06/30/16'

    WHEN GetDate() Between '07/01/16' and '06/30/17' Then '06/30/17'

    WHEN GetDate() Between '07/01/17' and '06/30/18' Then '06/30/18'

    WHEN GetDate() Between '07/01/18' and '06/30/19' Then '06/30/19'

    WHEN GetDate() Between '07/01/19' and '06/30/20' Then '006/30/20'

    END)

    Select *

    From #TempLocation

    ***SQL born on date Spring 2013:-)

  • Nevermind, I figured it out. Forgot some Parntheses..:blush:

    ***SQL born on date Spring 2013:-)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply