Why does RIGHT(@foostr, 0) return NULL when @foostr is varchar(max)?

Posted by bob-montgomery on Stack Overflow See other posts from Stack Overflow or by bob-montgomery
Published on 2010-06-10T20:45:39Z Indexed on 2010/06/10 20:53 UTC
Read the original article Hit count: 236

Filed under:
|
|

In SQL Server 2005

If I want to find the right-most one character of a varchar(max) variable, no problem:

declare @foostr varchar(max)
set @foostr = 'abcd'
select right (@foostr, 1)

----
d

If I want to find the right-most zero characters of a string literal, no problem:

select right ('abcd', 0)

------------------

It returns an empty string.
If I want to find the right-most zero characters of a varchar(10), no problem:

declare @foostr varchar(10)
set @foostr = 'abcd'
select right (@foostr, 0)

----

It returns an empty string.
If I want to find the right-most zero characters of a varchar(max), well:

declare @foostr varchar(max)
set @foostr = 'abcd'
select right (@foostr, 0)

----    
NULL

It returns NULL. Why?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2005