Gaurav Raj

Gaurav Raj

  • 1.4k
  • 475
  • 33k

Implicit conversion from data type nvarchar to varbinary is

Mar 31 2019 2:24 AM
CREATE TABLE [dbo].[RegisterTable] (
    [Id]             INT           IDENTITY (1, 1) NOT NULL,
    [Name]           NVARCHAR (50) NULL,
    [email]          NVARCHAR (50) NULL,
    [HashPassword]   BINARY (32)   NULL,
    [ActivationCode] INT           NULL,
    [verify]         INT           NULL,
    [Date]           DATE          NULL,
    [Time]           TIME (7)      NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC)
);
insert into RegisterTable (Name,email,HashPassword,ActivationCode,verify)
values ('mn','mn@yahoo.com',(select HASHBYTES('SHA2_256','12345')),124,0)
 
CREATE PROCEDURE [dbo].[LoginProcedure]
    @Email nvarchar(50),
    @HashPass varbinary(32)
AS
    SELECT name from RegisterTable
    where email=@Email or HashPassword =CONVERT(varbinary(MAX), HASHBYTES('SHA2_256', @HashPass))
RETURN 0
 
 
USE [C:\USERS\RAAAZZ\DOCUMENTS\VISUAL STUDIO 2013\WEBSITES\WEBSITE1\APP_DATA\DATABASE.MDF]
GO

DECLARE    @return_value Int

EXEC    @return_value = [dbo].[LoginProcedure]
        @Email = N'mn@yahoo.com',
        @HashPass = N'12345'

SELECT    @return_value as 'Return Value'
 
 
when i exec login procedure i got error
Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query.
how can i solve it
 
 
 

Answers (2)