All, I have the following table called Foo which is the output of a complex PIVOT query

I need to remove rows in this table which have (DB1, DB2, DB3) all NULL. To do this normally we could use something like
DELETE FROM Foo
WHERE [DB1] IS NULL
AND [DB2] IS NULL
AND [DB3] IS NULL;
but the problem is that this code is called from C# and the columns (DB1, DB2, DB3) will change from execution-to-execution.
How can I do this dynamically?
Thanks for your time.
Edit1. I have another table Bar that contains the avalible DB# columns, so it is possible to use this table SELECT DISTINCT ... to get the list of columns I need in the WHERE clause. However, I have never done this before and am not sure where to start… Any help is appreciated.
Edit2. I cannot use C# in any way. The C# code is a parser of SQL, and works with the given .sql file. This has to be done entirely in SQL.
sp_executesqlallows you to execute a SQL string built up in SQL script.http://msdn.microsoft.com/en-us/library/ms188001.aspx
From your bar table