String or binary data would be truncated in SQL

Sometimes I faced this issue like string or binary data would be truncated  in SQL database.


The query that is executed by me was..


 

 drop table if exists #Empattendanceday
 create table #Empattendanceday
  (
 Today datetime,

 DayName nvarchar(8)

 )

 insert into #Empattendanceday

 SELECT GETDATE(), 'Wednesday'



The reason Behind this error is the length of datatype(nvarchar) is dayname is 8 character and we are inserting data more than 8 char i.e 9

That's why it gives us  this error


String or binary data would be truncated.

The statement has been terminated.


So try to keep datatype character more than inserting value or DayName nvarchar(max).



No comments:

Post a Comment