I want to find the number of nulls for a col_name. I am using the code below in SSMS:
DECLARE @NumNull INT = N'SELECT COUNT(*) FROM ' + @WhichTable + N' WHERE col_name IS NULL'
I have declared @WhichTable as NVARCHAR(MAX) at the beginning of my procedure.
I am getting this error message:
Msg 245, Level 16, State 1, Procedure sp_FILL_CHAIN_NAMES, Line 22
Conversion failed when converting the nvarchar value 'SELECT COUNT(*) FROM UNION_ALL WHERE col_name IS NULL' to data type int.
I am not sure how to rewrite this SQL code? I tried exec(), and even SQL but it does not seem to be working!
INT? - Eric