Error converting nvarchar to int data type

I get an error

Error converting nvarchar to int data type

the code:

ALTER procedure [dbo].[sp_rcdoc]
  @regno int,
  @appname varchar(50),
  @DOI datetime,
  @COV varchar(50),
  @validtill date,
  @imgloc varchar(500),
  @ImagNo char(20),
  @Purposecode varchar(50),
  @FLAG varchar(3)
AS BEGIN
   IF NOT EXISTS(SELECT regno FROM tblRCDocuments WHERE regno = @regno)
   BEGIN
       INSERT INTO tblRCDocuments(regno, appname, DOI, COV, validtill, imgloc, ImagNo, Purposecode, FLAG) 
       VALUES(@regno, @appname, @DOI, @COV, @validtill, @imgloc, @ImagNo, @Purposecode, @FLAG)
   END
+5
source share
1 answer

It looks like regno is the nvarchar data type in your table, and you passed int through your procedure, either use the @regno cast for nvarchar, or change the regno data type to an integer in the table.

DECLARE @regnocast NVARCHAR(15)

SET @regnocast = CAST(@regno AS NVARCHAR)

Then in your SELECT, INSERT, and WHERE clauses, use @regnocast, not @regno

+8
source

All Articles