Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    1

    Unanswered: Why can varchar datatype variable only 4000 byte?

    Why can varchar datatype variable only 4000 byte?
    For example:
    in a storedprocedure
    declare @aa varchar(8000)
    ......
    while
    select @aa=@aa+@otherinfo
    end
    when the length is more than 4000 ,the data in the behind will be lost

  2. #2
    Join Date
    Mar 2004
    Posts
    45
    My guess is that @otherinfo is nvarchar type. Nvarchar has higher precedence than varchar, so the result of an operation (concatenation in this case) will take the type of the operand with higher precedence. The result is then implicitly converted to the type of the variable receiving the result.

    declare @aa varchar(8000), @otherinfo nvarchar(4000)
    set @aa = replicate('X',4000)
    set @otherinfo = @aa
    set @aa = @aa + @otherinfo
    select len(@aa)

    Hans.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •