Select

  • I want to create a stored procedure who return the first day for the last twelves month.

    To return the last month i use

    SELECT

    CONVERT(datetime,CONVERT( varchar(10) , DATEADD("Day",-(DAY(GetDate()) - 1),GetDate()),103),103)

    So if i do this for all the month i have a result like '01/01/2005' '01/02/2005' '01/03/2005'

    How can i have the result in a column ?

    01/01/2005

    01/02/2005

    01/03/2005

    Thanks

  • Something like this?

    DECLARE @OneYearAgo DATETIME

    SET @OneYearAgo  = DATEADD(YEAR,-1,DATEADD(MONTH,DATEDIFF(MONTH,0,GETDATE()),0))

    SELECT @OneYearAgo

    SELECT DATEADD(MONTH, Number, @OneYearAgo)

      FROM master..spt_values

     WHERE Type='P' AND Number BETWEEN 1 AND 12

     

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Exactly what i need, and it's ingenious !

    Thanks a lot Frank

    Sylvain

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

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