| Author |
Topic |
|
Grifter
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-04-01 : 06:12:18
|
| Hi allI'm running an insert into statement and getting the following error on the last two insert lines:Server: Msg 8152, Level 16, State 9, Line 1String or binary data would be truncated.The statement has been terminated.Server: Msg 8152, Level 16, State 9, Line 1String or binary data would be truncated.The statement has been terminated.Now if I reduce the string size in the field it does not do this. Currently the string is about 60 long and the size for the column is 100, if i reduce the string size down to say 20 it works ok.Why is this, the original string length is still < 100 ?Thanks for any suggestionsG |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-01 : 06:20:47
|
Can you show the table structure and what you are doing in your statement? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-04-01 : 06:25:34
|
Trailing spaces? - ignored by LEN() by considered by DATALENGTH()Actually I don't think that is the case. SQL will silently trim trailing spaces to make the field fit, but will not trim actual characters!CREATE TABLE #TEMP( MyTarget varchar(4))DECLARE @MyString varchar(10)SELECT @MyString = 'ABC 'SELECT LEN(@MyString), DATALENGTH(@MyString), '[' + @MyString + ']'INSERT INTO #TEMP (MyTarget) VALUES (@MyString)SELECT '[' + MyTarget + ']'FROM #TEMPSELECT @MyString = 'ABC X'SELECT LEN(@MyString), DATALENGTH(@MyString), '[' + @MyString + ']'INSERT INTO #TEMP (MyTarget) VALUES (@MyString)SELECT '[' + MyTarget + ']'FROM #TEMPGODROP TABLE #TEMPGO ----------- ----------- ------------ 3 6 [ABC ]------ [ABC ] ----------- ----------- ------------ 7 7 [ABC X]Server: Msg 8152, Level 16, State 14, Line 18String or binary data would be truncated.The statement has been terminated. |
 |
|
|
Grifter
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-04-01 : 06:27:48
|
| Table Structure:3 DiscardID int 4 00 Description varchar 100 00 Label varchar 50 00 AcceptanceLevel int 4 00 NumLabels int 4 00 ProductTypes varchar 100 0Problem is with 2nd column 'description'trying to insert like this, these are the last two rows that fail:INSERT INTO TableA ([Description], Label, AcceptanceLevel, NumLabels, ProductTypes) VALUES ('Product processing not initiated within acceptable time limit', 'Discard', 1, 0, 'Value,ValueA,ValueAB'))INSERT INTO TableA ([Description], Label, AcceptanceLevel, NumLabels, ProductTypes) VALUES ('Product processing not completed within acceptable time limit', 'Discard', 1, 0, 'Value,ValueA,ValueAB') |
 |
|
|
Grifter
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-04-01 : 06:31:56
|
| When I cut down the large string in the first column it works ok but as I said the length it is now is under 100. |
 |
|
|
Grifter
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-04-01 : 06:53:07
|
| Anyone? |
 |
|
|
Grifter
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-04-01 : 07:01:15
|
| Ah I got it, someone has changed the column size in the DB I am working on to 100 but this change is not reflected in any alter table script, the size was only 50 in the other DB I am putting the values in! |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-04-01 : 07:01:33
|
| "Problem is with 2nd column 'description'"You sure its not with ProductTypes column? (or any other VARCHAR column?Any trigger etc?The exact error message will show you which Object the error is in - in particular check that is NOT the name of a trigger or somesuch. |
 |
|
|
Grifter
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-04-01 : 07:19:42
|
| ""Problem is with 2nd column 'description'"You sure its not with ProductTypes column? (or any other VARCHAR column?"No definitely the description column.fixed now as the size was to small. I was pulling data from a table the same but the size had been increased, but not in new table. |
 |
|
|
|