Problem when generating one in SQL server to show them in an xtraReport?

0

When generating the query for the dates in SQL the result is correct, but when I put it in separate queries, when I want to see it in XtraReport only shows me the first one, my question is how could I solve this problem ? either from the query or XtraReport .

CREATE PROCEDURE [dbo].[AsistenciaDeMaestros] 
(@datFechaInicial DATE,
 @datFechaFinal DATE
)
AS
BEGIN
    SET NOCOUNT ON;
    WHILE(@datFechaInicial<=@datFechaFinal)
    BEGIN

IF ((DATEPART(dw,@datFechaInicial)=1) OR(DATEPART(dw,@datFechaInicial)=2)OR (DATEPART(dw,@datFechaInicial)=3)OR
(DATEPART(dw,@datFechaInicial)=4)OR(DATEPART(dw,@datFechaInicial)=5))

BEGIN

  SELECT strDia=(DATENAME(dw, @datFechaInicial)),strFecha=(@datFechaInicial)

END

    SET @datFechaInicial=DATEADD(day, 1, @datFechaInicial)
END
END
    
asked by Dan 15.10.2016 в 17:09
source

1 answer

0

One solution may be to create a temporary table, adding the rows there and then doing a single select. The problem with the current procedure is that it makes a selection for each date.

CREATE PROCEDURE [dbo].[AsistenciaDeMaestros] 
    (@datFechaInicial DATE,
     @datFechaFinal DATE
    )
    AS
    BEGIN
        SET NOCOUNT ON;

        create table ##temporal(strDia  nvarchar(15),strFecha smalldatetime )

        WHILE(@datFechaInicial<=@datFechaFinal)
        BEGIN

    IF ((DATEPART(dw,@datFechaInicial)=1) OR(DATEPART(dw,@datFechaInicial)=2)OR (DATEPART(dw,@datFechaInicial)=3)OR
    (DATEPART(dw,@datFechaInicial)=4)OR(DATEPART(dw,@datFechaInicial)=5))

    BEGIN

       insert into ##temporal values (DATENAME(dw, @datFechaInicial), @datFechaInicial)

    END

        SET @datFechaInicial=DATEADD(day, 1, @datFechaInicial)
    END

        select * from ##temporal
    END
    
answered by 15.10.2016 в 18:39