• sharonsql2013 (6/26/2014)


    I need to compare the ACC_Backlog data for the last two months. The table has monthwise data from May 2013 until May 2014. I am only looking for last two months comparision.

    So, if ACC_Backlog of may 2014 is > april then it should display "1" or "Higher" else 0 or "lower"

    Here is the existing query, Can anyone advise?

    Select Month_Year

    ,datepart(month, cast(replace(Month_Year, '-', '') as datetime)) as MyMonth

    , datepart(year, cast(replace(Month_Year, '-', '') as datetime)) as MyYear

    ,Group

    ,ACC_Opened

    ,ACC_Closed

    ,ACC_Backlog

    ,Time_Stamp

    from ACC_ByMonth

    WHERE Group = 'Investments'

    --ORDER By MyYear desc , MyMonth desc

    How about some ddl and sample data? Can you change the table so that Month_Year is a date or datetime instead of character data? It will save you tons of pain in the long run.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/