Here is a brute force path, since you know all the column names.
CREATE TABLE dbo.splunge ( a INT, b INT, c INT, d INT ); INSERT dbo.splunge VALUES (0,0,1,-1), (0,NULL,0,0), (0,0,0,NULL); SELECT cols = STUFF( CASE WHEN MIN(COALESCE(a,0)) = MAX(COALESCE(a,0)) THEN ',a' ELSE '' END + CASE WHEN MIN(COALESCE(b,0)) = MAX(COALESCE(b,0)) THEN ',b' ELSE '' END + CASE WHEN MIN(COALESCE(c,0)) = MAX(COALESCE(c,0)) THEN ',c' ELSE '' END + CASE WHEN MIN(COALESCE(d,0)) = MAX(COALESCE(d,0)) THEN ',d' ELSE '' END, 1, 1, '') FROM dbo.splunge;
You could probably generate most of this script instead of doing it manually, assuming you know the naming scheme or data type of the columns you want (or just leaving the where clause completely and deleting the columns you want to manually).
SELECT CHAR(13) + CHAR(10) + ' + CASE WHEN MIN(COALESCE(' + name + ',0)) = ' + 'MAX(COALESCE(' + name + ',0)) THEN '',' + name + ''' ELSE '''' END' FROM sys.columns WHERE [object_id] = OBJECT_ID('dbo.splunge')
The result will look like the middle of the first request, so you can copy and paste and then delete the first + and add the surrounding STUFF and the request ...