Hi @Carlton Patterson ,
Please try the following solution.
It is using SQL Server XML and XQuery powers without dynamic SQL and cursors.
The algorithm is very simple.
When we are converting each row into XML, columns that hold NULL value are missing from the XML.
After that set operator EXCEPT
brings us those missing columns comparing them with the full set of columns of the table.
SQL
USE tempdb;
GO
DROP TABLE IF EXISTS #tmpTable;
CREATE TABLE #tmpTable (
client_id int,
client_name varchar(500),
client_surname varchar(500),
city varchar(500),
state varchar(500));
INSERT #tmpTable VALUES
(1,'Miriam',NULL,'Las Vegas',NULL),
(2,'Astrid',NULL,'Chicago',NULL),
(3,'David',NULL,'Phoenix',NULL),
(4,'Hiroki',NULL,'Orlando',NULL);
SELECT name
FROM tempdb.sys.columns
WHERE object_id = object_id('tempdb..#tmpTable')
AND is_nullable = 1
EXCEPT
SELECT x.value('local-name(.)', 'SYSNAME')
FROM #tmpTable AS t
CROSS APPLY (SELECT t.* FOR XML PATH(''), TYPE, ROOT('root')) AS t1(c)
CROSS APPLY c.nodes('/root/*') AS t2(x);
Output
+----------------+
| name |
+----------------+
| client_surname |
| state |
+----------------+