none
Msg 8152:String or binary data would be truncated

    Question

  • I am getting this error

    Msg 8152, Level 16, State 14, Line 1

    String or binary data would be truncated.

    The statement has been terminated.

    AND

    I am using this query:

    INSERT INTO WSD.dbo.TRANSFERHISTORY 

    (FROMAGENCYID, FROMSERVICESITEID, TOAGENCYID, TOSERVICESITEID, WI_ID, MODIFYDTTM, MODIFYUSERID)

    SELECT FROM_AGENCY_ID, FROM_CLINIC_CODE, TO_AGENCY_ID, TO_CLINIC_CODE, ID_NUMBER, LAST_UPDATE_DATE, LAST_UPDATE_BY FROM 

    WSDCO.dbo.BOOKMARK

    I think its related to the Length of the data type ID_NUMBER varchar(9) and WI_ID varchar(8). 

    So what is the solution for this???


    dimrd_SQL
    Monday, February 28, 2011 5:23 PM

Answers

  • You can use LEFT(ID_NUMBER,8) instead of ID_NUMBER if you can not fix the structure of the TransferHistory table to match your other table structure exactly.
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Marked as answer by Ai-hua Qiu Tuesday, March 08, 2011 7:46 AM
    Monday, February 28, 2011 5:30 PM
    Moderator

All replies

  • You can use LEFT(ID_NUMBER,8) instead of ID_NUMBER if you can not fix the structure of the TransferHistory table to match your other table structure exactly.
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Marked as answer by Ai-hua Qiu Tuesday, March 08, 2011 7:46 AM
    Monday, February 28, 2011 5:30 PM
    Moderator
  • Hi,

    i dont think there is as solution rather than increasing your WI_ID column size.

    Can you fill a beaker of 2L capacity with 3 L water???


    Thanks and regards, Rishabh
    Monday, February 28, 2011 5:30 PM
  • Hi, Errors of the Severity Level 16 are generated by the user and are corrigible by the user. The statement cannot be executed this way. You must either shorten the string to be isnerted to widen the column.

    http://social.msdn.microsoft.com/Forums/en/transactsql/thread/ec184168-ddd1-4df5-b2c7-c6671b602a3d

     

    • Edited by SqlRockss Monday, February 28, 2011 6:16 PM Added Link
    Monday, February 28, 2011 6:13 PM