Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 string or binary data would be truncated issue

Author  Topic 

learntsql

524 Posts

Posted - 2014-01-06 : 11:38:36
Hi All,

I am loading data into table and for one of the columns i am getting an error saying "string or binary data would be truncated".
But i am sure that the data is coming less than that column size.
I tested this by taking the final output into Temp table and checked the sizes for all the rows.
But i am not sure why this error is coming.
Can anyone please guide me on this.
TIA.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-01-06 : 12:01:17
could it be a column other than the one you tested? compare the structure (all columns) of the Temp table you successfully loaded with the actual target table.
If you want specific help you'll have to post some code.

Be One with the Optimizer
TG
Go to Top of Page

learntsql

524 Posts

Posted - 2014-01-06 : 12:27:55
Hi TG,

Thank you for the quick reply.
Before loading into actual table i loaded into temp table using select * into statement and then i checked the column data the size is less than the column size as i mentioned.
but temp table column size is showing as varchar(8000).
sorry i am unable to post the code.
Please guide me.
TIA.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-01-06 : 13:17:49
It might be that there are trailing blanks or something. Is the source column data type a CHAR maybe? If you want to eliminate the error you can CAST/Convert the source column to the size/length of the destination column. But, make sure that you aren't actually truncating a string and loosing data.
Go to Top of Page

hotdog
Starting Member

3 Posts

Posted - 2014-01-06 : 14:52:22
You never say howyou are loading the data... Are you loading it via a stored proc with parameters? Parameters can also throw that error if you are passing a varchar(50) into a varchar(25) column.

"If you don't have the time to do it right, you definitely don't have the time to do it over."
Go to Top of Page

learntsql

524 Posts

Posted - 2014-01-06 : 23:05:55
Thank you all,

I tried it by casting the data then it worked.
Let me also try with other work arounds...
Please let me know if any other solutions.
Thanks a lot...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-07 : 01:05:59
quote:
Originally posted by learntsql

Thank you all,

I tried it by casting the data then it worked.
Let me also try with other work arounds...
Please let me know if any other solutions.
Thanks a lot...


It may be some unprintable characters too. how did you determine the length?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -