CAST DATE i.e 1=Jan, 2=Feb, 3=March etc....

  • I have the following code:

    SELECT DATEPART(yyyy, TRADE_DATE) as Year, DATEPART(M, TRADE_DATE) as Month, AVG (Commission)AverageCommission

    FROMtbldeals

    WHERE

    DATEPART(YYYY, TRADE_DATE) in ('2009', '2008') AND

    Commission

    NOT LIKE '0'

    ANDTRADEID

    Not in ('0000001','0000002')

    ANDCurrency not like 'ZAR'

    group by datepart(M, trade_date), DATEPART(yyyy, TRADE_DATE)

    ORDER BY DATEPART(yyyy, TRADE_DATE), datepart(M, trade_date)

    Gives me the following results:

    Year Month Value

    2008 1 936.862827496758

    2008 2 842.732158894646

    2008 3 918.247053854277

    2008 4 1033.89184549356

    2008 5 980.340058479532

    In the Month column how do I convert:

    1=Jan, 2=Feb, 3=March etc....

  • Look up DATENAME in BOL

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537
  • try it

    select datename(month,TRADE_DATE)

    fromtbldeals

  • Fantastic, worked fine.

Viewing 4 posts - 1 through 3 (of 3 total)

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