on 09-30-2015 5:14 PM
Hola expertos, estoy tratando de convertir un campo de "Hora" pero me muestra un error: Conversion failed when converting date and/or time from character string
SELECT
case len (t0.createtime)
when 3 then convert(time,substring(convert(nvarchar,t0.createtime),1,1)
+':'+ substring(convert(nvarchar,t0.createtime),2,2))
when 4 then convert(time,substring(convert(nvarchar,t0.createtime),1,1)
+':'+ substring(convert(nvarchar,t0.createtime),2,2))
end
FROM OSCL T0
Oscar,
Intenta con esto:
SELECT
convert(time,left(right('0000' + createtime, 4), 2) + ':' + right(right('0000' + createtime, 4), 2)) [Hora]
FROM OSCL T0
Saludos y suerte,
JC.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hola Juan Carlos, intenté pero me muestra el siguiente error:
1). [Microsoft][SQL Server Native Client 10.0][SQL Server]El identificador formado por varias partes "t0.createtime" no se pudo enlazar. 2). [Microsoft][SQL Server Native Client 10.0][SQL Server]No se puede preparar la instrucción o instrucciones. '' (SWEI)
copio y pego
SELECT
convert(time,left(right('0000' + createtime, 4), 2) + ':' + right(right('0000' + createtime, 4), 2)) [Hora]
FROM OSCL T0
pero me muestra el siguiente mensaje estimado:
1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Debe especificar la tabla en la que hacer la selección. 2). [Microsoft][SQL Server Native Client 10.0][SQL Server]No se puede preparar la instrucción o instrucciones. 'Alertas recibidas' (OAIB)
Hola Oscar, yo tengo algo similar en Crystal Reports para mostrar la hora en formato hora. Igual de aquí sacas una idea:
If Len(cstr({OPDN.U_HoraPesoBruto},'#')) = 4 Then
left(cstr({OPDN.U_HoraPesoBruto},'#'),2) + ":" + Right(cstr({OPDN.U_HoraPesoBruto},'#'),2) + ' Hrs'
else
left(cstr({OPDN.U_HoraPesoBruto},'#'),1) + ":" + Right(cstr({OPDN.U_HoraPesoBruto},'#'),2) + ' Hrs'
Suerte.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.