The problem is that I need to use a generic method which do not know the field length...
Main Topics
Browse All TopicsHi,
Server: Msg 8152, Level 16, State 9, Line 1
String or binary data would be truncated.
The statement has been terminated.
This error happen when I tried to insert a value too long in a varchar column:
(insert "123456" in a column varchar(3))
Is there a way to tell the server to truncate the value and insert it ?
any Server Option ?
I don't mind if the value is truncate, but I have to make sure the value is inserted...
Thanks
Mary
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I'm not sure where you are going with that, but another idea would be to query the field length from syscolumns and store the length in a variable. You can use the length variable with the LEFT as stated above to determine where to chop the value.
I would write a function for this as it would be the easiest.
Business Accounts
Answer for Membership
by: frodomanPosted on 2003-12-01 at 09:08:19ID: 9851392
How about:
INSERT LEFT("123456",3) INTO .....
This will truncate before attempting to insert.