EmpezarEmpieza gratis

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

Ver curso

Instrucciones del ejercicio

  • Crea una variable de tipo time llamada @ShiftStartTime y asígnale el valor inicial '08:00 AM'.
  • Crea una variable de tipo date llamada @StartDate y asígnala al primer StartDate de la tabla BikeShare.
  • Crea una variable de tipo datetime llamada `@ShiftStartDateTime.
  • Cambia @StartDate y @ShiftStartTime a 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
Editar y ejecutar código