DECLARE & CAST
Usemos DECLARE() y CAST() para combinar una variable de fecha y una variable de hora en una variable de tipo datetime.
Este ejercicio forma parte del curso
Escritura de funciones y procedimientos almacenados en SQL Server
Instrucciones del ejercicio
- Crea una variable de tipo
timellamada@ShiftStartTimey asígnale el valor inicial'08:00 AM'. - Crea una variable de tipo
datellamada@StartDatey asígnala al primerStartDatede la tablaBikeShare. - Crea una variable de tipo
datetimellamada`@ShiftStartDateTime. - Cambia
@StartDatey@ShiftStartTimea tipos de datos datetime y asigna el resultado a@ShiftStartDateTime.
ejercicio interactivo práctico
Prueba este ejercicio completando este código de ejemplo.
-- 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