I am trying to drop empty columns from a pivot table to reduce the width of the table to make it easier to see on the page.
I have 67-69 date columns in a pivot table that I am trying to review and drop if they have no value. On review of other questions via AI and this community that were somewhat related I found a sample code snippet that I adjusted to my content. Everything is saving, but the columns are not being dropped from the Pivot Table. Tried many different changes, but cannot seem to get it to work. Any thoughts?
SET @hasValue = (SELECT SUM("Jun 15,2026") FROM T1) IS NULL;
IF @hasValue BEGIN
ALTER TABLE T1 DROP COLUMN 'Jun 15,2026';
END;
SELECT * FROM T1