How do I add quarter to my dates table

  • Hi I have got a dates table containing every possible date ftill 2017.

    It has got a counter field and date field. Now I need to add an extra column called 'Quarter' which shows the year and quarter for the dates.

    here is the result table i want

    Counter Date Quarter

    1 1/1/2005 Q1/2005

    2 23/11/2006 Q4/2006

    3 12/4/2000 Q2/2000

    Please help guys

    Thnks

  • UPDATE Table1

    SET Quarter = 'Q' + DATENAME(QUARTER, Date) + '/' + DATENAME(YEAR, Date)


    N 56°04'39.16"
    E 12°55'05.25"

  • If you load your date table with the function on this link, it has columns for quarters and many other date attributes built in.

    Date Table Function F_TABLE_DATE:

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519

  • Since the data is already in the table, it seems a bit much to store it another time but in a different format. How about using a view or a computed column?

    http://www.sqlservercentral.com/articles/T-SQL/61764/

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Thank you so much!!v :hehe:

    That exactly what I wanted

    God bless

    Cheers

    😀

  • Nuts (2/12/2008)


    That exactly what I wanted

    Just curious... which way did you end up going exactly?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 6 posts - 1 through 5 (of 5 total)

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