DECLARE & CAST
Let's use DECLARE() and CAST() to combine a date variable and a time variable into a datetime variable.
Cet exercice fait partie du cours
Writing Functions and Stored Procedures in SQL Server
Instructions
- Create a
timevariable named@ShiftStartTimeand set initial value to'08:00 AM'. - Create a
datevariable named@StartDateand set it to the firstStartDatefrom theBikeSharetable. - Create a
datetimevariable named`@ShiftStartDateTime. - Change
@StartDateand@ShiftStartTimeto datetime data types and assign to@ShiftStartDateTime.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
-- 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