SQL Count for each date

后端 未结 7 692
盖世英雄少女心
盖世英雄少女心 2021-02-03 21:57

I have the following need

I have a logging table which logs som leads generated each day.

Now I need to pull a report over the amount of leads for each day over

7条回答
  •  长发绾君心
    2021-02-03 22:30

    CREATE PROCEDURE [dbo].[sp_Myforeach_Date]
        -- Add the parameters for the stored procedure here
        @SatrtDate as DateTime,
        @EndDate as dateTime,
        @DatePart as varchar(2),
        @OutPutFormat as int 
    AS
    BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.
        Declare @DateList Table
        (Date varchar(50))
    
        WHILE @SatrtDate<= @EndDate
        BEGIN
        INSERT @DateList (Date) values(Convert(varchar,@SatrtDate,@OutPutFormat))
        IF Upper(@DatePart)='DD'
        SET @SatrtDate= DateAdd(dd,1,@SatrtDate)
        IF Upper(@DatePart)='MM'
        SET @SatrtDate= DateAdd(mm,1,@SatrtDate)
        IF Upper(@DatePart)='YY'
        SET @SatrtDate= DateAdd(yy,1,@SatrtDate)
        END 
        SELECT * FROM @DateList
    END
    

    Just put this Code and call the SP in This way

    exec sp_Myforeach_Date @SatrtDate='03 Jan 2010',@EndDate='03 Mar 2010',@DatePart='dd',@OutPutFormat=106
    

    Thanks Suvabrata Roy ICRA Online Ltd. Kolkata

提交回复
热议问题