I have a question about how I can make queries in SQL Server with hours fields.
I have a column called hora_inicio_prestamo
and another hora_fin_prestamo
, both of type time(0)
, I also have a column called Estado_prestamo
what I need is to separate the hours between those hours and say if they are on loan .
Example:
________________________________________________________________
|Hora_inicio_prestamo |Hora_fin_prestamo | Estado_prestamo |
----------------------------------------------------------------
|7:00 | 11:00 | EN PRESTAMO |
----------------------------------------------------------------
(You could make temporary fields like this)
Hora | Estado
7:00 ---> EN PRESTAMO
8:00 ---> EN PRESTAMO
9:00 ---> EN PRESTAMO
10:00 ---> EN PRESTAMO
11:00 ---> EN PRESTAMO
12:00 ---> LIBRE
13:00 ---> LIBRE
I tried to create dynamic fields with CAST
, like this:
SELECT Id_prestamo_laboratorio
,CAST('' AS TIME(0)) AS Siete
,CAST('' AS TIME(0)) AS Ocho
,CAST('' AS TIME(0)) AS Nueve
FROM PrestamoLaboratorios