0

I have table containing column Email which is varchar(MAX) and I am trying to update it using stored procedure. When the string length is greater than 8000 characters, I get this error

String or binary data would be truncated. The statement has been terminated.

Stored procedure:

ALTER PROCEDURE [dbo].[SaveData]
    @Id BIGINT,
    @Email varchar(max)
AS
BEGIN
    SET NOCOUNT ON;

    UPDATE tb_data
    SET Email = @Email
    WHERE Id = @Id  
END

Please note that datatype for email is set to varchar(MAX)

Interesting thing is when I try to run the update query manually, it works!

I've done this several times but cannot figure out why it's not working in this case.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sangram Nandkhile
  • 17,634
  • 19
  • 82
  • 116

1 Answers1

-1

Hope this can help you:

Microsoft MSDN

Maximum Capacity Specifications for SQL Server

1 byte = 1 character >> 2^31-1 characters

varchar [ ( n | max ) ]

Variable-length, non-Unicode string data. n defines the string length and can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size is the actual length of the data entered + 2 bytes. The ISO synonyms for varchar are char varying or character varying.

How many characters in varchar(max)

Maximum size of a varchar(max) variable

Community
  • 1
  • 1
japzdivino
  • 1,736
  • 3
  • 17
  • 25