“veraltet in SQL Server” Code-Antworten

veraltet in SQL Server

SELECT DATEDIFF(dd, '2017/08/25', '2011/08/25') AS DateDiff
--result
-2192
Kalineo

SQL erhält die Anzahl der Tage zwischen zwei Daten

DATEDIFF(DAY, '1/1/2011', '3/1/2011')
Lazy Lemur

So erhalten Sie das Datum Diff auf das Feld "SQL Server" auf einmal

SELECT t1.OrderNo,DATEDIFF(day,t1.LoadedStartDate,t2.LoadedStartDate)
FROM UnnamedTableFromQuestion t1
       INNER JOIN
     UnnamedTableFromQuestion t2
       on
         t1.OrderNo = t2.OrderNo
WHERE t1.OpNo = 1 and
      t2.OpNo = 4
      
////////////////////////////////////////////////////////////////

select cur.unique_id_field, cur.seq_no, cur.date_created ,

  datediff(second, prv.date_created, cur.date_created) as diff_in_seconds

from yourtable as cur

  join yourtable as prv

    on cur.seq_no = prv.seq_no + 1;
Kandyman

SQL datiff Monat

CREATE FUNCTION FullMonthsSeparation 
(
    @DateA DATETIME,
    @DateB DATETIME
)
RETURNS INT
AS
BEGIN
    DECLARE @Result INT

    DECLARE @DateX DATETIME
    DECLARE @DateY DATETIME

    IF(@DateA < @DateB)
    BEGIN
        SET @DateX = @DateA
        SET @DateY = @DateB
    END
    ELSE
    BEGIN
        SET @DateX = @DateB
        SET @DateY = @DateA
    END

    SET @Result = (
                    SELECT 
                    CASE 
                        WHEN DATEPART(DAY, @DateX) > DATEPART(DAY, @DateY)
                        THEN DATEDIFF(MONTH, @DateX, @DateY) - 1
                        ELSE DATEDIFF(MONTH, @DateX, @DateY)
                    END
                    )

    RETURN @Result
END
GO

SELECT dbo.FullMonthsSeparation('2009-04-16', '2009-05-15') as MonthSep -- =0
SELECT dbo.FullMonthsSeparation('2009-04-16', '2009-05-16') as MonthSep -- =1
SELECT dbo.FullMonthsSeparation('2009-04-16', '2009-06-16') as MonthSep -- =2
Bad Butterfly

Ähnliche Antworten wie “veraltet in SQL Server”

Fragen ähnlich wie “veraltet in SQL Server”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen