By Falk Krahl
CREATE TABLE dbo.UTCZeit
(Startzeit datetime, Endzeit datetime, Differenz int)
GO
INSERT INTO UTCZeit VALUES ('28.03.2010 02:00:01', '31.10.2010 03:00:00', 2)
,('01.01.2011 00:00:00', '27.03.2011 02:00:00', 1)
,('27.03.2011 02:00:01', '30.10.2011 03:00:00', 2)
,('30.10.2011 03:00:01', '25.03.2012 02:00:00', 1)
,('25.03.2012 02:00:01', '28.10.2012 03:00:00', 2)
,('28.10.2012 03:00:01', '31.03.2013 02:00:00', 1)
,('31.03.2013 02:00:01', '27.10.2013 03:00:00', 2)
,('27.10.2013 03:00:01', '26.10.2014 03:00:00', 1)
,('30.03.2014 02:00:01', '26.10.2014 03:00:00', 2)
,('26.10.2014 03:00:01', '31.12.2014 23:59:59', 1)
GO
CREATE FUNCTION dbo.fn_UTCZeit (@Datum smalldatetime)
RETURNS smalldatetime as
BEGIN
DECLARE @Offset INT
SELECT @Offset = Differenz FROM UTCZeit
WHERE @Datum BETWEEN Startzeit AND Endzeit
SET @Datum = DATEADD(HOUR, isnull(@Offset,0), @Datum)
RETURN @Datum
END
GO
SELECT [Ankunftszeit] AS AnkunftszeitUTC
, [Abfahrtszeit] AS AbfahrtszeitUTC
, dbo.UTCZeit([[Ankunftszeit]]) AS AnkunftszeitNOR
, dbo.UTCZeit([Abfahrtszeit]) AS AbfahrtszeitNOR
FROM [dbo].[Tabelle]
GO
Das Ergebniss sieht dann wie folgt aus:
AnkunftszeitUTC: 2012-03-25 00:55:00.000
AbfahrtszeitUTC: 2012-03-25 02:10:00.000
AnkunftszeitNOR: 2012-03-25 01:55:00
AbfahrtszeitNOR: 2012-03-25 04:10:00