Showing Quarters Dynamically

  • mandymvn

    Mr or Mrs. 500

    Points: 547

    Hi,

    At present am showing quarters from 2015-Q1 to Q4 , it should be like that, because report must show data for last 4 quarters only.

    Whenever i got data for "2016-Q1" then automatically report should change and display data for "2016-Q1" - "2015-Q4" - "2015-Q3" - "2015-Q2", it should be based on current quarter. same for upcoming quarters also.

    Is it possible??

    again this is for reporting purpose only... there is 4 sets of query and using UNION

    and also in the logic its hard coded as:

    '2015 01' AS Qtr from Table WHERE (YYYYMM = 201503)

    UNION

    '2015 02' AS Qtr from Table WHERE (YYYYMM = 201506)

    UNION

    '2015 03' AS Qtr from Table WHERE (YYYYMM = 201509)

    UNION

    '2015 04' AS Qtr from Table WHERE (YYYYMM = 201512).

    please let me know if anyone need more details.

  • Alan Burstein

    SSC Guru

    Points: 61026

    Duplicate thread. Direct any esponses to http://www.sqlservercentral.com/Forums/Topic1766578-3412-1.aspx

    -- Alan Burstein


    Helpful links:Best practices for getting help on SQLServerCentral -- Jeff ModenHow to Post Performance Problems -- Gail ShawNasty fast set-based string manipulation functions:For splitting strings try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL Server 2012+)To split strings based on patterns try PatternSplitCMNeed to clean or transform a string? try NGrams, PatExclude8K, PatReplace8K, DigitsOnlyEE, or Translate8KI cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code.  -- Itzik Ben-Gan 2001

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

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