July 18, 2013 at 8:53 am
Hello
I am inserting data from one table to another using update,set command and getting the following error.
SET XDDdepositor.WBeneName = Vendor.RemitName,
XDDDepositor.WBeneAddr = Vendor.RemitAddr1,
XDDDepositor.WBeneAddr2 = Vendor.RemitAddr2,
XDDDepositor.WBeneCity = Vendor.RemitCity,
XDDDepositor.WBeneState = Vendor.RemitState,
XDDDepositor.WBeneZipPostal = Vendor.RemitZip
From XDDDepositor, Vendor
Where XDDDepositor.vendid like '05%'and
XDDDepositor.vendid = Vendor.Vendid and
XDDDepositor.WBeneName =''
ERROR:
Msg 8152, Level 16, State 14, Line 2
String or binary data would be truncated.
The statement has been terminated.
I know the problem is the character length of the address columns I am inserting data from but is there a way to correct it without altering the columns being updated?
WBenBankAddr (char(35),not null) and RemitAddr1 (char(60), not null)
WBeneAddr2 (char(35),not null) and RemitAddr2 (char(60), not null)
July 18, 2013 at 8:57 am
Use LEFT function to limit number of characters to be taken from columns which causing this problem.
P.S. Without having DDL of tables involved it's impossible to tell which exact columns causing this problem. I guess you know them yourself...
July 18, 2013 at 9:16 am
Here is how you would do that for the two columns you say are the problem.
update XDDDepositor
SET XDDdepositor.WBeneName = Vendor.RemitName,
XDDDepositor.WBeneAddr = left(Vendor.RemitAddr1, 35),
XDDDepositor.WBeneAddr2 = left(Vendor.RemitAddr2, 35),
XDDDepositor.WBeneCity = Vendor.RemitCity,
XDDDepositor.WBeneState = Vendor.RemitState,
XDDDepositor.WBeneZipPostal = Vendor.RemitZip
From XDDDepositor, Vendor
Where XDDDepositor.vendid like '05%'and
XDDDepositor.vendid = Vendor.Vendid and
XDDDepositor.WBeneName =''
The potential issue that you are only copying some of the data. If you need to hold all the information you will have to make the destination columns wide enough to hold the data.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 18, 2013 at 9:21 am
LEFT, SUBSTRING, you need to limit the amount of data updated, as Eugene noted.
July 18, 2013 at 10:09 am
Thanks Sean that worked. I also found that substring worked too.
update XDDDepositor
SET XDDdepositor.WBeneName = Vendor.RemitName,
XDDDepositor.WBeneAddr = SUBSTRING( Vendor.RemitAddr1,0, 35),
XDDDepositor.WBeneAddr2 = SUBSTRING( Vendor.RemitAddr2, 0 , 35),
XDDDepositor.WBeneCity = Vendor.RemitCity,
XDDDepositor.WBeneState = Vendor.RemitState,
XDDDepositor.WBeneZipPostal = Vendor.RemitZip
From XDDDepositor, Vendor
Where XDDDepositor.vendid like '05%'
and XDDDepositor.vendid = Vendor.Vendid
and XDDDepositor.WBeneName =''
July 18, 2013 at 10:10 am
Thanks
Thanks Sean that worked. I also found that substring worked too.
update XDDDepositor
SET XDDdepositor.WBeneName = Vendor.RemitName,
XDDDepositor.WBeneAddr = SUBSTRING( Vendor.RemitAddr1,0, 35),
XDDDepositor.WBeneAddr2 = SUBSTRING( Vendor.RemitAddr2, 0 , 35),
XDDDepositor.WBeneCity = Vendor.RemitCity,
XDDDepositor.WBeneState = Vendor.RemitState,
XDDDepositor.WBeneZipPostal = Vendor.RemitZip
From XDDDepositor, Vendor
Where XDDDepositor.vendid like '05%'
and XDDDepositor.vendid = Vendor.Vendid
and XDDDepositor.WBeneName =''
July 18, 2013 at 12:06 pm
your last bracket is missing a / before the word code. /code
July 18, 2013 at 12:46 pm
jdbrown239 (7/18/2013)
ThanksThanks Sean that worked. I also found that substring worked too.
That is because in this case they are doing the same thing. 😉
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 18, 2013 at 3:32 pm
jdbrown239 (7/18/2013)
ThanksThanks Sean that worked. I also found that substring worked too.
update XDDDepositor
SET XDDdepositor.WBeneName = Vendor.RemitName,
XDDDepositor.WBeneAddr = SUBSTRING( Vendor.RemitAddr1,0, 35),
XDDDepositor.WBeneAddr2 = SUBSTRING( Vendor.RemitAddr2, 0 , 35),
XDDDepositor.WBeneCity = Vendor.RemitCity,
XDDDepositor.WBeneState = Vendor.RemitState,
XDDDepositor.WBeneZipPostal = Vendor.RemitZip
From XDDDepositor, Vendor
Where XDDDepositor.vendid like '05%'
and XDDDepositor.vendid = Vendor.Vendid
and XDDDepositor.WBeneName =''
Rather than just truncating the address, you may want to use the REPLACE() function to substitute long words with common abbreviation or remove unneeded spaces.
http://www.semaphorecorp.com/cgi/abbrev.html
For example:
XDDDepositor.WBeneAddr =
SUBSTRING( REPLACE( REPLACE(
Vendor.RemitAddr1
, 'BOULEVARD', 'BLVD' )
, 'EXPRESSWAY', 'EXPY' )
, 0, 35 )
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply