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.
if you're storing foreign key reference table (in case,
departmentid
on employee tableid
field on department table), need of same data type. if don't have foreign key reference defined, should. ensure referential integrity , prevent errors this.when storing
null
in field, need sure you're storing actualnull
value rather string containing "null" (which looks you're doing in case). it's conversion causing error.
Comments
Post a Comment