Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit conversion from data type varchar to varbinary is not allowed. (SQL)

Error:

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

Any question? I am new to SQL Server

USE schemas
GO

CREATE PROCEDURE Table
    @LineaNegocioId INT,  --null
    @PaisId INT, -- required
    @AreaId INT, --required
    @Nombre VARCHAR(100), --required
    @Descripcion VARCHAR(100), --required 
    @fechaCreacion DATETIME, --required
    @fechaUltimaModificacion DATETIME --null
AS 
BEGIN
    SET NOCOUNT ON

    INSERT INTO Table (LineaNegocioId, PaisId, AreaId, Nombre, Descripcion, fechaCreacion, fechaUltimaModificacion)
    VALUES (@LineaNegocioId, @PaisId, @AreaId, @Nombre, @Descripcion, @fechaCreacion, @fechaUltimaModificacion)

    SET NOCOUNT OFF
END
like image 598
DanyMartinez_ Avatar asked Jul 13 '18 17:07

DanyMartinez_


People also ask

Can we convert varchar to varbinary in SQL Server?

Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query. The problem is that the query plan hashes are already in binary format, however stored as VARCHAR in the XML Query Plan e.g.

What is Varbinary in SQL?

varbinary [ ( n | max ) ]Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length.

When would you use Varbinary data type?

The VARBINARY data type holds variable-length binary data. Use this type when the data is expected to vary in size. The maximum size for VARBINARY is 8,000 bytes. As an aside, the word VARBINARY stands for varying binary.

What is the difference between binary and varbinary in SQL Server?

Even though BINARY and VARBINARY are binary byte data types, they have differences when it comes to storage. BINARY stores values in fixed lengths while VARBINARY stores in variable depending on the type of values. Values in BINARY data type are padded with 0x00 which is not the case with VARBINARY.


1 Answers

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]) ,...)

like image 195
Edward Avatar answered Oct 13 '22 21:10

Edward