LoslegenKostenlos loslegen

DECLARE & CAST

Let's use DECLARE() and CAST() to combine a date variable and a time variable into a datetime variable.

Diese Übung ist Teil des Kurses

Writing Functions and Stored Procedures in SQL Server

Kurs anzeigen

Anleitung zur Übung

  • Create a time variable named @ShiftStartTime and set initial value to '08:00 AM'.
  • Create a date variable named @StartDate and set it to the first StartDate from the BikeShare table.
  • Create a datetime variable named `@ShiftStartDateTime.
  • Change @StartDate and @ShiftStartTime to datetime data types and assign to @ShiftStartDateTime.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

-- Create @ShiftStartTime
___ ___ AS time = '08:00 AM'

-- Create @StartDate
___ ___ AS date

-- Set StartDate to the first StartDate from CapitalBikeShare
___ 
	___ = (
    	SELECT TOP 1 ___ 
    	FROM CapitalBikeShare 
    	ORDER BY StartDate ASC
		)

-- Create ShiftStartDateTime
___ ___ AS datetime

-- Cast StartDate and ShiftStartTime to datetime data types
___ @ShiftStartDateTime = ___(___ AS datetime) + ___(___ AS datetime) 

SELECT @ShiftStartDateTime
Code bearbeiten und ausführen