Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

T-SQL INSERT INTO; Problem with data truncation error

$
0
0

SQL Version:  2008 R2

PROBLEM:  I'm having issues with the following code involving an INSERT INTO statement.  I'm getting the error "String of binary data would be truncated.  The statement has been terminated."  The problem only occurs when I increase the value to be inserted into the RoleID by more than 4 characters.  This field is declared at nvarchar(1000) so I don't understand why this is happening.  If I reduced the length to four characters, say 'ABCD', the code runs fine.  If I increase it to five characters, say 'ABCDE', I get the truncation error.

Any ideas would be appreciated.  The offending code and a screen shot are below.

OFFENDING CODE

BEGIN --Create Table #OldRoles
 CREATE TABLE #OldRoles (
     JCCo int
   , JobNum varchar(100)
   , PMID int
   , Name nvarchar(100)
   , RoleID nvarchar(1000)
   , VPUserName nvarchar(100)
   )
END  


INSERT INTO #OldRoles (JCCo, JobNum, PMID, Name, RoleID, VPUserName)
  SELECT JCJM.JCCo, JCJM.Job, JCJM.udProjectBIC, JCMP.Name, 'ABCDE', JCMP.udVPUserName
   FROM JCJMPM AS JCJM
    JOIN JCMP ON JCJM.JCCo = JCMP.JCCo AND JCJM.ProjectMgr = JCMP.ProjectMgr
   WHERE
     JCMP.udVPUserName IS NOT NULL
    AND JCMP.ProjectMgr IS NOT NULL
    AND JCJM.udProjectBIC IS NOT NULL
    AND JCJM.JCCo = 1
    AND JCJM.Job LIKE '%091040%'


Bob Sutor


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>