3

I have a table with a VARBINARY(MAX) column and I've tried inserting values into this table but I can't.

The QUERY is:

INSERT INTO [I_RACEDB].[dbo].[tce_lineno]([lineNo] ,[testCaseName] ,[project])
 VALUES (<lineNo, varchar(250),> ,<testCaseName, varbinary(max),>,<project, varchar(100),>)

INSERT INTO [I_RACEDB].[dbo].[tce_lineno] ([lineNo],[testCaseName],[project])
     VALUES ('44','TestCase_TestCheck01_Mail_Validation','proj001')

The ERROR is:

Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.

How can I insert values?

careyes17
  • 9
  • 5
user3114967
  • 639
  • 5
  • 15
  • 38

1 Answers1

8

The error is self explaining.

Use convert(VARBINARY(max), 'TestCase_TestCheck01_Mail_Validation')

I.e.:

INSERT INTO [I_RACEDB].[dbo].[tce_lineno] ([lineNo],[testCaseName],[project])
VALUES ('44',convert(VARBINARY(max), 'TestCase_TestCheck01_Mail_Validation'),'proj001')
Giorgi Nakeuri
  • 35,155
  • 8
  • 47
  • 75
  • And you now have the first 30 bytes of data in the table. You might want to specify a length on that [`varbinary`](https://msdn.microsoft.com/en-us/library/ms188362.aspx) – Damien_The_Unbeliever Feb 03 '15 at 07:23