Why do I get nvarchar value null to a data type in SQL Server 2008? -


i getting error in sql server:

conversion failed when converting nvarchar value 'null' data type int.

in employee table have:

id int,  name nvarchar(50), gender nvarchar(10),  salary nvarchar(50),  departmentid nvarchar(50) 

nulls allowed departmentid.

in department table have:

id int,  department name nvarchar(50), location nvarchar(50),  departmentheead nvarchar(50) 

none of them allow nulls.

i trying join tables so:

select name, gender, salary, departmentname employee join department on employee.departmentid = department.id 

that's when error:

conversion failed when converting nvarchar value 'null' data type int.

i not understanding error here. goal join departmentname column employee table.

  1. if you're storing foreign key reference table (in case, departmentid on employee table id field on department table), need of same data type. if don't have foreign key reference defined, should. ensure referential integrity , prevent errors this.

  2. when storing null in field, need sure you're storing actual null value rather string containing "null" (which looks you're doing in case). it's conversion causing error.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -