question

mahi222 avatar image
mahi222 asked

string or binary data truncated error in procedure please help me on this

Please refer the below statement where I am getting the eror like Msg 8152, Level 16, State 13, Procedure sp_Org_Master, Line 209 String or binary data would be truncated. Please refer below the double quoted line is showing the error UPDATE xxx SET xxx.[IsInFactory] = 1, xxx.[FAC_isMerged] = mss.[IsMerged], xxx.[FAC_TPID] = mss.[TPID], xxx.[FAC_SubSegmentID] = mss.[EndCustomerSubSegmentID], xxx.[FAC_VerticalCategoryID] = mss.[VerticalCatID], --xxx.[FAC_FY_TPID] = ss.FinalTPID, -- recommended value xxx.[FAC_FY_SubSegmentID] = mss.[SubSegmentAltID], xxx.[FAC_FY_VerticalCategoryID] = mss.[VerticalCategoryAltID], xxx.[FAC_IsFYTopParent] = (CASE WHEN mss.[IsFYTopParent] = 'Yes' THEN 1 ELSE 0 END), ----- missing geo & name xxx.[SubsidiaryId] = COALESCE(xxx.[SubsidiaryId], mss.[WWSubsidiaryID]), xxx.[CountryID] = COALESCE(xxx.[CountryID], mss.[EndCustomerCountryID]), xxx.[OrgName] = COALESCE(xxx.[OrgName], mss.[OrgName]) FROM [audit].[t_Org_Master_staging] AS xxx "JOIN [DW].[FAC].[t_MSSInfo] AS mss (NOLOCK)" ON mss.[MSSID] = xxx.[OrgID] AND mss.[OrgTypeID] = 7 AND mss.[IsInternalOrg] = 0;
string
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

seanlange avatar image seanlange commented ·
You have a couple of bad code smells in here. First you are using NOLOCK. Are you aware of what that hint brings to the table? Are you ok with missing and/or duplicated data? You also left off the keyword WITH. This keyword being optional is deprecated and you should include it when you use hints. I would recommend not using hints at all but that is another topic. http://blogs.sqlsentry.com/aaronbertrand/bad-habits-nolock-everywhere/ Then you mention you have a procedure named sp_*. I do not like prefixes personally but if you use them you should avoid the sp_ prefix as that is reserved for MS system procedures. http://sqlperformance.com/2012/10/t-sql-queries/sp_prefix
0 Likes 0 ·

1 Answer

·
JohnM avatar image
JohnM answered
I'm guessing that isn't the line causing the issue. That error is stating that one of the source values is larger than the destination column can hold, which would result in SQL Server truncating the value. I'd look at those two tables to see if one of the destination columns (audi.t_org_master_staging) is smaller than one of the source columns.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mahi222 avatar image mahi222 commented ·
i am also thinking on same thing thank you very much this is really helpful to me
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.