Change column from VARCHAR(MAX) to VARBINARY(MAX)
You cannot perform this conversion using an ALTER TABLE
statement since converting from varchar(max)
to varbinary(max)
requires an explicit conversion. So you should follow these steps to alter your table:
- Alter table with new column of
VARBINARY(MAX)
- If you have existing data in the
VARCHAR(MAX)
column, use update statement to add the data to theVARBINARY
column - Alter table to drop the
VARCHAR(MAX)
column - Rename
varbinary
column tovarchar
name (per comment from @Ben Thul)
Implicit conversion from data type varchar to varbinary is not allowed. (SQL)
Either the field Nombre
or Descripcion
is a varbinary
and you must explicitly convert
those inputs for your insert
clause.
It would look like this.
VALUES (... ,CONVERT(varbinary, [@Nombre or @Descripcion]) ,...)
Error converting VarChar to VarBinary in SQL Server
Hmm, AFEE27AF97DC6
is one nibble short and it seems like only full bytes are accepted. Try to zero pad it. E.g.
SELECT convert(varbinary(max), '0AFEE27AF97DC6', 2)
You can also wrap it in a CASE
expression checking if the string has an even or odd length, should the strings be variable.
SELECT convert(varbinary(max),
CASE
WHEN len('AFEE27AF97DC6') % 2 <> 0 THEN
concat('0', 'AFEE27AF97DC6')
ELSE
'AFEE27AF97DC6'
END,
2)
(Replace the literals with your variable.)
Convert varchar(max) to varbinary(max)
you are using wrong Syntax for CONVERT
https://msdn.microsoft.com/en-in/library/ms187928.aspx
-- Syntax for CONVERT:
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
try to use this
update DocumentOnline
set FileData = CONVERT(VARBINARY(max), 0x255044462D312E340A25E2E3CFD30A322030206F626A0A3C3C2F4C656E6774682034392F46696C7465722F466C6174654465636F64653E3E73747265616D0A789C2BE4720AE1323653B03030530849E1720DE10AE42A54305430004208999CABA01F9166A8E092AF10C80500EAA209F20A656E6473747265616D0A656E646F626A0A342030206F626A0A3C3C2F5265736F75726365733C3C2F584F626A6563743C3C2F586631203120)
where ClientId = '54528' and EndDate = '201607'
Implicit conversion from data type varchar to varbinary(max) is not allowed c#
I think that better solution will be using SqlParameter like this:
cmd.Parameters.Add("@Biometric", SqlDbType.VarBinary, 8000).Value = bTemplateDataOne;
Error converting data type varchar to varbinary in sql only for few values
You're passing a style of 1
to CONVERT
.
If the data_type is a binary type, the expression must be a character expression. The expression must be composed of an even number of hexadecimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, a, b, c, d, e, f). If the style is set to 1 the characters 0x must be the first two characters in the expression. If the expression contains an odd number of characters or if any of the characters are invalid an error is raised.
My emphasis.
All of your examples of invalid sequences appear to have odd lengths. You should add a padding 0
if you have an odd length sequence. Whether you pad at the start or the end depends on your exact requirements, where the sequence came from, etc.
Related Topics
Order by Column1 If Column1 Is Not Null, Otherwise Order by Column2
Sql Server Login Disable Windows Authentication
Whats The Best Sqlite Data Type for a Long String
Count Max. Number of Concurrent User Sessions Per Day
Migrating Oracle Date Columns to Timestamp with Timezone
Adodataset Deleting from Joined Table
How to Group by One Column and Retrieve a Row with The Minimum Value of Another Column in T/Sql
In Oracle, Is Starting The SQL Query's Where Clause with 1=1 Useful
MySQL Select Within If Statement
How to Automatically Reset a Sequence's Value to 0 Every Year in Oracle 10G
Failed to Create an Assembly in Sql
Sql Server, Using a Table as a Queue
Error While Uploading a Report
Display Zero by Using Count(*) If No Result Returned for a Particular Case
Cannot Connect to SQL Server Express from Ssms
Why Does This Oracle Drop Column Alter The Default Value of Another Column
Composing Database.Esqueleto Queries, Conditional Joins and Counting