How do I check for a null or empty table-valued parameter?
A table can't be NULL
, nor can a TVP. How do you check if a table is empty? You certainly don't say IF Sales.SalesOrderHeader IS NULL
. :-)
IF EXISTS (SELECT 1 FROM @tvp)
BEGIN
-- lots of expensive processing
END
ELSE
BEGIN
-- a little bit of cheap processing
END
...
The table valued parameter isn't going to be null. Treat it more like a table and @aaraon Bertrand beat me to the punch. So yes, check for whether there are rows.