Not quite clear what it means
the field is empty provided it is not NULL
I think that it is necessary to proceed from what data is stored in this field, and what to take for "empty . "
See it. Suppose, for example, there is data:
declare @varData table (id int, value sql_variant); insert into @varData values (1, 1); insert into @varData values (2, 'AAAA'); insert into @varData values (3, 0.26); insert into @varData values (4, 0x); insert into @varData values (5, getdate()); insert into @varData values (6, ''); insert into @varData values (7, newid()); insert into @varData values (8, N' '); insert into @varData values (9, 0x0000);
If we mean "empty, but not NULL" in the sense that the length of an element is 0 bytes, then the function DATALENGTH is the closest in meaning. Request
select * from @varData where datalength(value) = 0
returns rows with id = 4 and id = 6 .
Strings whose field value is empty (in the ANSI-SQL sense) string will return the query
select * from @varData where value = ''
In this case, the row with id = 4 not returned (although the value of the value field is empty in the sense of the datalength criterion), but the rows with id = 6 returned (which is logical) and id = 8 (which is logical from the ANSI-SQL point of view, but can to be somewhat unexpected from the point of view, for example, C #, where the same string is not empty, although composed of white-space characters).
Lines whose field value is empty (again in the ANSI-SQL sense) sequence of bytes will return the query
select * from @varData where value = 0x
In this case, the string with id = 6 is not returned (although its value empty in the sense of the datalength criterion), and the rows are returned with id = 4 (which is logical) and id = 9 (which may again be somewhat unexpected from the point of view of C #, where 0x0000 byte array is not empty at all).
In general, choose a criterion based on what is required by the task and according to the data.
ps but in general for void it is better to use NULL