1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

query for first and last day of month

Discussão em 'Outras Linguagens' iniciado por Stack, Janeiro 21, 2021.

  1. Stack

    Stack Membro Participativo

    If I have the name of the month, how can I have the first and last day of that month in SQL?

    I have this query to returns the month names:

    DECLARE @StartDate DATETIME,
    @EndDate DATETIME;

    SELECT @StartDate = '20110501'
    ,@EndDate = '20110801';


    SELECT DATENAME(MONTH, DATEADD(MONTH, x.number, @StartDate)) AS MonthName
    FROM master.dbo.spt_values x
    WHERE x.type = 'P'
    AND x.number <= DATEDIFF(MONTH, @StartDate, @EndDate)


    Result:

    [​IMG]

    Now, how can i get the first and last day of that months? changing the query.

    Continue reading...

Compartilhe esta Página