Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Tasty很想知道你的答案,但尽管这可以奏效,但光标会根据我的口味变慢 select convert(date, r.LaadDatum), convert(date, r.LosDatum) from tblPlanning p _Sql_Sql Server_Sql Server 2014 - Fatal编程技术网

Sql Tasty很想知道你的答案,但尽管这可以奏效,但光标会根据我的口味变慢 select convert(date, r.LaadDatum), convert(date, r.LosDatum) from tblPlanning p

Sql Tasty很想知道你的答案,但尽管这可以奏效,但光标会根据我的口味变慢 select convert(date, r.LaadDatum), convert(date, r.LosDatum) from tblPlanning p ,sql,sql-server,sql-server-2014,Sql,Sql Server,Sql Server 2014,Tasty很想知道你的答案,但尽管这可以奏效,但光标会根据我的口味变慢 select convert(date, r.LaadDatum), convert(date, r.LosDatum) from tblPlanning p inner join tblRit r on p.RitID = r.RitID where r.ChauffeurID = 201 and (convert(date, r.LaadDatum) >= '20180812' a


Tasty很想知道你的答案,但尽管这可以奏效,但光标会根据我的口味变慢
select convert(date, r.LaadDatum), 
       convert(date, r.LosDatum)
from   tblPlanning p
  inner join tblRit r on p.RitID = r.RitID 
where  r.ChauffeurID = 201
and    (convert(date, r.LaadDatum) >= '20180812' and convert(date, r.LaadDatum) <= '20180921')
and    datediff(day, r.LaadDatum, r.LosDatum) > 1
COLUMN1     COLUMN2 
-------     ------- 
2018-08-14  2018-08-16  
2018-08-20  2018-08-22  
2018-09-01  2018-09-03  
2018-09-08  2018-09-10  
2018-09-14  2018-09-17  
2018-08-15  
2018-08-21  
2018-09-02  
2018-09-09  
2018-09-15  
2018-09-16  
;WITH CTE AS(
    SELECT DATEADD (DAY,1,COLUMN1) COLUMN1,COLUMN2
    FROM T
    UNION ALL
    SELECT DATEADD (DAY,1,COLUMN1) ,COLUMN2
    FROM CTE
    WHERE  DATEADD (DAY,1,COLUMN1)< COLUMN2
)
SELECT COLUMN1 
FROM CTE
ORDER BY COLUMN1
DECLARE @myTable AS TABLE (Column1 DATE, Column2 DATE);

INSERT INTO @myTable (Column1, Column2)
VALUES ('2018-08-14', '2018-08-16')
,      ('2018-08-20', '2018-08-22')
,      ('2018-09-01', '2018-09-03')
,      ('2018-09-08', '2018-09-10')
,      ('2018-09-14', '2018-09-17');

WITH cte AS
    (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) RN
       FROM master..spt_values)
SELECT          DATEADD(DAY,rn,Column1) DayToShow
  FROM          @myTable
 CROSS APPLY    cte
 WHERE DATEADD(DAY,rn,Column1) < column2
Declare @TempTable table (BetweenDate datetime)
Declare @FromDate datetime, 
        @ToDate datetime,
        @date datetime

Declare DatesCursor Cursor For
        Select FromDate, ToDate From (
                     select convert(date, r.LaadDatum) FromDate, 
                            convert(date, r.LosDatum) ToDate 
                     from   tblPlanning p
                        inner join tblRit r on p.RitID = r.RitID 
                     where  r.ChauffeurID = 201
                         and    (convert(date, r.LaadDatum) >= '20180812' 
                         and convert(date, r.LaadDatum) <= '20180921')
                         and    datediff(day, r.LaadDatum, r.LosDatum) > 1) t


    Open DatesCursor
    Fetch Next From DatesCursor Into @FromDate,  @ToDate

    While @@Fetch_Status = 0
    Begin
        If (@FromDate is not null and @ToDate is not null )
            Begin
                SET @date = DATEADD(day, 1, @FromDate) 
                WHILE (@date < @ToDate)
                BEGIN
                    insert @TempTable Values(@date)
                    SET @date = DATEADD(day, 1, @date) 
                END
        END
        Fetch Next From DatesCursor Into @FromDate,  @ToDate
    End

    Close DatesCursor

    select * from @TempTable