Forum Discussion
SQL Query Issue
- I get the error “String or binary data would be truncated.”
As the error message clearly says and the cause is
[dbo].[Table1] => [User_Id] [varchar](50)
[dbo].[table2] => [User_Id] [varchar](100)
- LainRobertsonSilver Contributor
I don't see any issue. Everything is behaving precisely as it should.
From table1, [User_Id] is set to a maximum of 50 characters while in table2, [User_Id] is set to 100 characters. Any standards-compliant SQL engine should throw an error if you try and INSERT [User_Id] from table2 into table1.
In your second example, you're truncating [User_Id] back down to a maximum of 30 characters, which fits into the limit of 50 from table 1, so there is no longer an error condition.
So, as I say, everything is fine and behaving exactly as it should.
Cheers,
Lain
- olafhelperBronze ContributorI get the error “String or binary data would be truncated.”
As the error message clearly says and the cause is
[dbo].[Table1] => [User_Id] [varchar](50)
[dbo].[table2] => [User_Id] [varchar](100)