[ Foro de SQL (y MySQL) ]

ERROR en SQL Server

04-Oct-2022 10:34
Sergi Garcia
2 Respuestas

Buenos días,

Agradecería que me ayudasen con el siguiente error en SQL SERVER.

Estoy intentando añadir datos de forma masiva que me han pasado en un .SQL , tengo una tabla llamada "producto" con un campo llamado "fabricación" que indica el año de fabricación de cada producto insertado. ese campo ya lo tengo marcado como "SmallDateTime"

El problema es que cuando ejecuto la instrucción para añadir el listado de productos me lanza el siguiente error:

"The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value."

Lo que más me extraña es que hay productos con el formato de la fecha exactamente iguales ej: 24/08/2020  y  15/05/2019   y en uno me tira el error y en el otro no!  

A continuación copio el Script que ejecuto y el log que me devuelve por consola.  Si os fijais me está dando el error en productos con aparentemente valores del mismo tipo en todos los campos...  

A alguien se le ocurre que está pasando?¿

Soy novato!!!  MUCHAS GRACIAS!


AQUÍ ABAJO EL SCRIPT QUE EJECUTO.

-------------------------------------------------------------------------------------------------------------

use Facturas


insert into Producto
(nombre,precio,modelo,cantidad,marca,fabricacion,valoracion)
values
('Placa Base',40.50,'HTX 500',6,'Asus','20200130',7.0)

insert into Producto
values
('Tarjeta gráfica',110.99,'Óptima',4,'Nvidia','29-01-2020 12:30',6.9)

insert into Producto
values
('Placa base',60.49,'PBX 12',6,'Gigabyte','29/01/2020',7.0)

insert into Producto
values
('Tarjeta Sonido',99.99,'Sound Class',8,'Sound Blaster',CURRENT_TIMESTAMP,8.0)

insert into Producto
(nombre,precio,modelo,cantidad,marca)
values
('Monitor',130,'UltraVision',1,'LG')

insert into Producto
values
('Procesador',190.75,'I5 6000',10,'Intel','19/05/2020',8.3)

insert into Producto
values
('Procesador',230.10,'I7 7500',10,'Intel','14/02/2020 11:30',8.5)

insert into Producto
values
('Procesador',310.05,'I9 Ultra',6,'Intel','14/02/2020 12:30',9.5)

insert into Producto
values
('Procesador',290.12,'Ryzen 7',6,'AMD','14/02/2020 17:45',9.2)

insert into Producto
values
('Procesador',110.22,'Pentium III',10,'Intel','26/02/1999',3.5)

insert into Producto
values
('Memoria RAM',55.95,'DDR3 Extreme 8GB',6,'Kingston',CURRENT_TIMESTAMP,5.5)

insert into Producto
values
('Memoria RAM',29.90,'DDR4 4GB',16,'Kingston','15/02/2020',4.9)

insert into Producto
values
('Memoria RAM',130.90,'DDR4 16GB',10,'Toshiba','28/02/2020',5.3)

insert into Producto
values
('Tarjeta Gráfica',130.45,'Extreme 1.0',6,'AMD','18/02/2018',5.4)

insert into Producto
values
('Tarjeta Gráfica',310.80,'Extreme 2.0',6,'AMD','28/02/2019',6.4)

insert into Producto
values
('Tarjeta Gráfica',530.99,'Extreme 3.0 Gaming',6,'AMD','01/03/2020',8.6)

insert into Producto
values
('Tarjeta Gráfica',615.25,'Extreme 4.0 Gaming WoW',4,'AMD','11/04/2020',9.8)

insert into Producto
values
('Tarjeta Sonido',100.20,'Sound Max',1,'Sound Blaster','04/03/2017',8.0)

insert into Producto
values
('Fuente alimentacion',34.50,'ATX4',6,'Gigabyte','13/03/2019',5.0)

insert into Producto
values
('Disco Duro',90.80,'4 TB-zztop',8,'Seagate','25/02/2020',7.3)

insert into Producto
values
('Disco Duro',50.45,'1TB-x2450',8,'Seagate','25/01/2018',5.3)

insert into Producto
values
('Disco Duro',90.45,'2TB-x3550',8,'Seagate','15/04/2018',7.0)

insert into Producto
values
('Disco Duro',49.80,'SSD240',20,'Kingston','25/05/2018',6.8)

insert into Producto
values
('Disco Duro',67.80,'SSD500 Memo',10,'Kingston','25/04/2020',7.5)

insert into Producto
values
('Disco Duro',179.79,'SSD1000 Memo',5,'Kingston','21/05/2020',8.5)

insert into Producto
values
('Disco Duro',120.80,'HDD-40-1TB',8,'Samsung','15/08/2019',6.9)

insert into Producto
values
('Monitor',195.80,'24kyt',1,'Samsung','25/11/2017',6.9)

insert into Producto
values
('Monitor',230.80,'27ERC',1,'Samsung','12/04/2019',7.8)

insert into Producto
values
('Monitor',240.50,'27Curve Gaming Pro',1,'AOC','19/04/2020',9.5)

insert into Producto
values
('Monitor',520.20,'32Curvemax',1,'AOC','29/05/2020',9.9)

insert into Producto
(nombre,precio,cantidad,marca)
values
('Ratón',5.30,40,'ElGato')

insert into Producto
values
('Ratón',49.90,'Gaming 2.0',10,'Logitech','07/02/2015',8.3)

insert into Producto
values
('Raton',99.85,'Gaming 3.0',10,'Logitech','09/12/2018',8.8)

insert into Producto
values
('Raton',120.35,'Gaming 4.0 4000DPI',1,'Logitech','09/10/2020',8.9)

insert into Producto
values
('Teclado',27.10,'Leds 400',8,'Logitech','03/02/2020',4.2)

insert into Producto
values
('Teclado',43.50,'Leds 600',8,'Logitech','09/06/2020',6.5)

insert into Producto
values
('Tarjeta Wifi',32.50,'4RDC/11',6,'TPLink','03/02/2019',5.0)

insert into Producto
values
('Torre',57.30,'Station 120',1,'NOX','03/03/2020',4.9)

insert into Producto
values
('Torre',98.60,'LED 2000',1,'NOX','03/03/2015',7.5)

insert into Producto
values
('Torre',118.50,'LED 3000',1,'NOX','03/04/2016',7.2)

insert into Producto
values
('Teclado',45.80,'Ergonomic 2',10,'Microsoft','13/03/2019',8.9)

insert into Producto
values
('Impresora',81.80,'Ink 12',1,'HP','18/03/2020',7.5)

insert into Producto
values
('Impresora',50.99,'Paper GTX',1,'HP','01/04/2020',7.1)

insert into Producto
values
('Impresora',110.29,'Paper GTX2',1,'HP','01/03/2020',7.9)

insert into Producto
values
('Plotter',800.49,'',1,'HP','11/04/2020',8.9)

insert into Producto
values
('Televisión',99.99,'22A14',1,'Samsung','11/04/2019',5.9)

insert into Producto
values
('Televisión',399.99,'47EDS',1,'Samsung','11/04/2020',7.5)

insert into Producto
values
('Televisión',2999.89,'55Tx-300',1,'LG','11/05/2020',9.2)

insert into Producto
values
('Televisión',900.05,'47D',1,'LG','11/06/2020',7.2)

insert into Producto
(nombre,precio,cantidad)
values
('Papel Impresora',1.70,16)

----------------------------------------------------------------------------------------------------------------------


AQUÍ ABAJO EL LOG QUE ME DEVUELVE



(1 fila afectada)
Mens. 242, Nivel 16, Estado 3, Línea 9
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 13
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.

(1 fila afectada)

(1 fila afectada)
Mens. 242, Nivel 16, Estado 3, Línea 26
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 30
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 34
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 38
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 42
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.

(1 fila afectada)
Mens. 242, Nivel 16, Estado 3, Línea 50
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 54
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 58
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 62
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)
Mens. 242, Nivel 16, Estado 3, Línea 78
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 82
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 86
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 90
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 94
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 98
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 102
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 106
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 110
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.

(1 fila afectada)
Mens. 242, Nivel 16, Estado 3, Línea 118
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 122
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)
Mens. 242, Nivel 16, Estado 3, Línea 167
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
Mens. 242, Nivel 16, Estado 3, Línea 171
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)

(1 fila afectada)


04-Oct-2022 22:01
Invitado (IIslas)

Maneja las fechas en formato ANSI yyyymmdd


05-Oct-2022 12:33
Nacho Cabanes (+83)

Tienes las fechas en varios formatos distintos. Parece que tu SQL Server está aceptando unos de esos formatos y rechazando otros. Deberás mirar cuáles son los que acepta (es algo que puede depender de la configuración regional) y convertir los demás a ese formato.






(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)