Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Alter Table help

Author  Topic 

d00d101
Starting Member

3 Posts

Posted - 2009-04-01 : 14:06:28
Ok... so this is what I have.

ALTER TABLE [Final PAR Calculations]
DROP COLUMN [Units of Order]

This will drop the specified column no matter what. But, what I want is for it to drop it only if the fields in that column are null. Is this possible? Or is there a way around it? I'm running data and building tables but, I don't want to always have to delete empty columns manually. It would be nice to have it automated. I've been searching and searching. Please help!!

Thanks,
d00d101

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-04-01 : 15:16:35
Dropping a column just because it's "empty" is not a good reason to do it. What happens if you need to put data in there, do you add the column back to the table? Better to just leave the column in place, if there's no data stored then there's little or no space wasted.
Go to Top of Page

d00d101
Starting Member

3 Posts

Posted - 2009-04-01 : 15:39:29
The Drop Column function will be put into a macro and added to a form. It will run last, once all data has been inserted into the final table. I won't need to add anymore data to the table once it's complete.
Go to Top of Page

dsindo
Starting Member

45 Posts

Posted - 2009-04-20 : 18:28:56
you don't really know which of the columns in your destination table is being populated? does your source randomly populate columns in you destination table?


if you must then:

f exists (
select sum(case when field_name is null then 1 else 0 end) ,count(*) from table_name
having sum(case when field_name is null then 1 else 0 end)=count(*) )
begin
alter table table_name drop column field_name
end
Go to Top of Page
   

- Advertisement -