Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error converting datatype nvarchar to int

I am getting the error

Error converting datatype nvarchar to int

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
like image 415
chandu Avatar asked Mar 31 '12 07:03

chandu


People also ask

What is the meaning of error converting data type NVARCHAR to numeric?

The error message tells you, the one column in one subsequent query is of type NVARCHAR, which cannot be converted implicitly.

How convert NVARCHAR value to datatype int in SQL Server?

1 Answer. "CONVERT" considers the column name, not the string that has the column name; your current expression is attempting to convert the string A. my_NvarcharColumn to an integer instead of the column content. SELECT convert (int, N'A.

How do I convert NVARCHAR?

Syntax: SELECT CONVERT(<DATA_TYPE>, <VALUE>); --DATA_TYPE is the type we want to convert to. --VALUE is the value we want to convert into DATA_TYPE. Example: SELECT 'Weight of Yogesh Vaishnav is ' + CONVERT(NVARCHAR(20), weight) AS person_weight FROM person WHERE name = 'Yogesh Vaishnav';

How do I convert varchar to numeric in SQL?

To convert a varchar type to a numeric type, change the target type as numeric or BIGNUMERIC as shown in the example below: SELECT CAST('344' AS NUMERIC) AS NUMERIC; SELECT CAST('344' AS BIGNUMERIC) AS big_numeric; The queries above should return the specified value converted to numeric and big numeric.


1 Answers

Looks like regno is a nvarchar data type in your table and you have passed an int via your your procedure, either use a cast and convert @regno to an 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 rather than @regno

like image 162
Darren Avatar answered Sep 28 '22 06:09

Darren