T-SQL Tutorial

Msg 245 Level 16 - Conversion failed when converting the varchar value


On Transact SQL language the Msg 245 Level 16 - Conversion failed when converting the varchar value means that you insert varchar values into an int column.

Msg 245 Level 16 Example:

We have the table TEST:

USE model;
GO
CREATE TABLE TEST(
   ID INT NOT NULL PRIMARY KEY,
   NAME VARCHAR(10) NOT NULL );
GO





Invalid insert:

USE model;
GO
INSERT INTO TEST(id, name) VALUES ('abc', 'Olivia');
GO

Message
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'abc' to data type int.

Correct insert:

USE model;
GO
INSERT INTO TEST(id, name) VALUES (1, 'Olivia');
GO

Message
(1 row(s) affected)

Other error messages: