Error message "String or Binary data would be trunicated", " The statement has been terminated"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff Magouirk

    Error message "String or Binary data would be trunicated", " The statement has been terminated"

    Dear All,

    I have written an update trigger that should write a message to an audit
    table When I try to update any field in the table I recieve the following
    error message -

    [ODBC Sql Server Driver] [Sql Server] Stirng or Binary data would be
    trunicated
    [ODBC Sql Server Driver] [Sql Server] The statement has been termined.

    I have looked and what has been suggested is to use the response.write len()
    to check the length of field that I am updating. Being fairly new to
    SQL-Server, I do not know how to do this. Any help will be most welcome.

    Thanks,

    Jeff


  • Erland Sommarskog

    #2
    Re: Error message "String or Binary data would be trunicated&quot ;, " The statement has been terminated&quot ;

    [posted and mailed. please reply in news]

    Jeff Magouirk (magouirkj@njc. org) writes:[color=blue]
    > I have written an update trigger that should write a message to an audit
    > table When I try to update any field in the table I recieve the following
    > error message -
    >
    > [ODBC Sql Server Driver] [Sql Server] Stirng or Binary data would be
    > trunicated
    > [ODBC Sql Server Driver] [Sql Server] The statement has been termined.
    >
    > I have looked and what has been suggested is to use the response.write
    > len() to check the length of field that I am updating. Being fairly new
    > to SQL-Server, I do not know how to do this. Any help will be most
    > welcome.[/color]

    The message means that you try to squeeze in a string into a column which
    does not fit the string.

    Judging from your description, the problem is in the trigger, so that is
    probably the code you need to scrutinize. Response.write len() sounds
    like somethnig webbish, so that is not likely to help you.

    A common error is to declare a column as varchar, without specifying
    any length. This results in a default of 1. In difference to client
    languages, a string always has a max length in SQL. (Which has to do
    with the fact that the string is to be persisted on disk.)

    --
    Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

    Books Online for SQL Server SP3 at
    Accelerate your AI application's time to market by harnessing the power of your own data and the built-in AI capabilities of SQL Server 2025, the enterprise database with best-in-class security, performance and availability.

    Comment

    • Steve Troxell

      #3
      Re: Error message "String or Binary data would be trunicated&quot ;, " The statement has been terminated&quot ;

      Jeff Magouirk wrote:[color=blue]
      > I have looked and what has been suggested is to use the
      > response.write len() to check the length of field that I am updating.
      > Being fairly new to SQL-Server, I do not know how to do this. Any
      > help will be most welcome.[/color]

      Response.Write is an ASP thing, not a SQL thing. You can't reference
      Response.Write within a trigger. Post your trigger and let's see what you
      have. The error indicates that you are trying to put a string into a field
      and the string is longer than the field is declared to be. You can suppress
      the error with SET ANSI_WARNINGS OFF, but the data itself will still be
      truncated to fit the field.

      --
      Steve Troxell


      Comment

      Working...