Jump to content

Recommended Posts

I am wanting to insert fields from a table (data types are varchar(50) into another empty table (who's data type is nvarchar(50)). I believe I have created the correct query to achieve this but received an error message when executing "Msg 8152, Level 16, State 4, Line 1 String or binary data would be truncated" Would these two data types be the cause of this? I'm using some other data types (int, bigint) that could possibly be the issue but these are the main ones used to I wanted to see about them first.

Link to post
Share on other sites
Insert into dbo.tblStaff   (StaffID, FirstName, LastName, JobID, StartDate, Email, SS)SELECT      	   [UserID]      ,[FirstName]      ,[LastName]      ,[JobCode]      ,[StartDate]      ,[EmailAddress]      ,[Keyword]  FROM [ACU].[dbo].[Users] WHERE [WebActive]='1' and [EndDate] IS NULL and [LoginName] like 'ABCDE%'
Link to post
Share on other sites

The error message means that the data is too long for the field.

Yes I was trying to get help as far as varchar and nvarchar so I could pinpoint which fields were to small. One table used nvarchar and the other used varchar so I was trying to see what the conversion for them would be if that makes sense.

example of data types that are trying to go into other data types are:

bigint ->int

varchar(50)->nvarchar(50)

Link to post
Share on other sites

nvarchar fields hold UTF characters, so they hold multi-byte strings. varchar fields do not hold multi-byte strings. You probably need to double the size of the nvarchar field to store the same string as the other field, because when it converts the string it's going to (at least) double the bytes for each character.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...