Hi Team

  • I am trying to Extract Month Name from specific Date field

    EXTRACT(MONTH From TO_DATE(PM_PROJ_BRIDGE.SELECT_DTE)) SELECT_MONTH_DAY, this Extract month Number

    C4

    how can I get month name  instead?

     

  • If you want just the month name, SELECT FORMAT(getdate(), 'MMMM')

     

    But ideally you would return the date as is and format it at display time.

  • ZZartin wrote:

    If you want just the month name, SELECT FORMAT(getdate(), 'MMMM')

    But ideally you would return the date as is and format it at display time.

    You don't want to do that if there are a lot of rows involved.  In fact, I urge folks to stop using FORMAT in SQL Server because it's so bad for performance that you shouldn't "practice doing it wrong" just for small row-counts.

    In SQL Server, SELECT DATENAME(mm,GETDATE()) will do the same thing as what the OP requested and much more quickly.

    Here's an article on the subject with some performance tests from simple to fairly complex.

    https://www.sqlservercentral.com/articles/how-to-format-dates-in-sql-server-hint-dont-use-format

     

    --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)

  • Guessing the OP is using MySQL - so this link might be useful: https://www.w3resource.com/mysql/date-and-time-functions/mysql-date_format-function.php

     

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • I thought it was someone trying to convert some other dialect to SQL Server.  🙁  I wish people would declare things like that.  Offering help in MySQL isn't a problem but it's difficult to guess that when they post in an SQLServer 2019 forum. 😀  I guess the reason they don't is because they probably think that SQL = SQL = SQL when it actually doesn't.

    In that's the case, then you certainly pointed at the correct documentation, Jeffrey.  Thanks.

    --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)

  • Jeff Moden wrote:

    I thought it was someone trying to convert some other dialect to SQL Server.  🙁  I wish people would declare things like that.  Offering help in MySQL isn't a problem but it's difficult to guess that when they post in an SQLServer 2019 forum. 😀  I guess the reason they don't is because they probably think that SQL = SQL = SQL when it actually doesn't.

    In that's the case, then you certainly pointed at the correct documentation, Jeffrey.  Thanks.

    That all depends on the OP - and it isn't clear if they are looking for help with MySQL or converting from MySQL to SQL Server.  If they are trying to convert then your recommendation is correct.  Hopefully the OP will respond and let us know for sure.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Jeffrey Williams wrote:

    That all depends on the OP - and it isn't clear if they are looking for help with MySQL or converting from MySQL to SQL Server.  If they are trying to convert then your recommendation is correct.

    Heh,,. yep... I kinda said that using different words.

    --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 7 posts - 1 through 6 (of 6 total)

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