What Transact-SQL nvarchar
value is not null and <> '' and datalength = 0?
I have a table with Field1
of data type nvarchar(max)
. For the value of Field1
in one particular record, the following statements are true:
- Field1 is not null
- DataLength(Field1) = 0
- Cast(IsNull(Field1, '') As nvarchar(1000)) is null
I am presuming Field1 <> ''
because Cast('' As nvarchar(1000))
is not null.
Background: Cast(IsNull(Field1, '') As nvarchar(1000)) is throwing an error from a stored procedure trying to insert that value where null is not allowed. When I modified the statement to use
IsNull(Cast(Field1 As nvarchar(1000)), '')
instead, things were happy. This issue has occurred twice in a remote clients database and I do not know how to reproduce it at will.
A backup copy of their database restored on my machine no longer had this issue. Is this some kind of database corruption? Or is there some character / collation combination that satisfies the conditions above?
Thank you for your input.