The topic describes the DF106 T-SQL code analysis rule.
EXECUTION RULES
Temporary table is used before having rows inserted into it.
It is recommended to ensure that the table has rows inserted before referencing it as a source table.
Referencing a temporary table before inserting rows may result in querying or joining against an empty table, leading to unexpected or inaccurate results. To avoid this, it’s recommended to ensure that a temporary table has rows inserted into it before referencing it as a data source in subsequent queries or operations.
DECLARE @Result TABLE(Id INT)
IF EXISTS(SELECT * FROM @result) SELECT 'Data found'
DECLARE @Result TABLE(Id INT)
INSERT INTO @Result(Id) SELECT Id FROM dbo.DemoTable WHERE Code = 'A'
IT EXISTS(SELECT * FROM @result) SELECT 'Data found'