I am trying to search within the values (table names) returned from a query to check if there is a record and some values in that record are null. If they are, then I want to insert the table's name to a temporary table. I get an error:
Conversion failed when converting the varchar value 'count(*)
FROM step_inusd_20130618 WHERE jobDateClosed IS NULL' to data type int.
This is the query:
DECLARE @table_name VARCHAR(150)
DECLARE @sql VARCHAR(1000)
DECLARE @test int
SELECT @table_name = tableName FROM #temp WHERE id = @count
SET @sql = 'SELECT * FROM ' + @table_name + ' WHERE jobDateClosed IS NULL'
--ERROR is below:
select @test = 'count(*) FROM ' + @table_name + ' WHERE jobDateClosed IS NULL'
--PRINT @sql
-- EXEC(@sql)
IF @test > 0
BEGIN
INSERT INTO #temp2 (tablename) VALUES ( @table_name);
END
SET @count = @count + 1
Any ideas how to convert the result of the count into an integer?