Error inserting data into a table in SQL Server 2008

1

I have a problem with the insertion of the following data in the following table:

CREATE TABLE TB_ADMIN_MONITOREO
(
    FECHA_PROCESO   NVARCHAR,
    FECHA_EJECUCION DATETIME,
    SERVIDOR        NVARCHAR,
    UNIDAD          CHAR,
    [LIBRE (MB)]    DECIMAL(15,2),
    [LIBRE (GB)]    DECIMAL(15,2),
    ESTADO          NVARCHAR
)
------------------------------------------------------------

insert TB_ADMIN_MONITOREO
values('20180423',GETDATE(), 'NEPTUNO','D',12.36, 45.23, 'RIESGO')

Result:

Mens. 8152, Nivel 16, Estado 4, Línea 1
String or binary data would be truncated.

I have already tried with Varchar , Nvarchar and none of them works for me. I'm not sure what the source of the problem is.

Greetings

    
asked by Fran.J 23.04.2018 в 23:16
source

2 answers

3

Because of the type of data you are using, the data is truncated if you send a value greater than the length since the length values are not defined ..

DECLARE  @TB_ADMIN_MONITOREO TABLE
(
    FECHA_PROCESO   DATETIME,
    FECHA_EJECUCION DATETIME,
    SERVIDOR        VARCHAR(50),
    UNIDAD          CHAR(1),
    [LIBRE (MB)]    DECIMAL(15,2),
    [LIBRE (GB)]    DECIMAL(15,2),
    ESTADO          VARCHAR(10)
)
------------------------------------------------------------

insert @TB_ADMIN_MONITOREO
values('20180423',GETDATE(), 'NEPTUNO','D',12.36, 45.23, 'RIESGO')

SELECT * FROM @TB_ADMIN_MONITOREO
    
answered by 23.04.2018 / 23:27
source
2

The problem is that the length of the field has not been defined, that is, you must say nvarchar(250)

CREATE TABLE TB_ADMIN_MONITOREO
(
    FECHA_PROCESO   NVARCHAR(25),
    FECHA_EJECUCION DATETIME,
    SERVIDOR        NVARCHAR(75),
    UNIDAD          CHAR,
    [LIBRE (MB)]    DECIMAL(15,2),
    [LIBRE (GB)]    DECIMAL(15,2),
    ESTADO          NVARCHAR(50)
)
    
answered by 23.04.2018 в 23:25