How can I drop a temp table column if the column that I want to drop has data in it? I can drop a temp table column if there is no data in it via something like:
...but I cannot get the column to drop if the column has any data in it. I get an error that says "Invalid column name". here's what I'm trying that gives me the error:
Does anyone have any clues on how to drop a temp table column with data in it?
Thanks for your help!!
Code:
create table #temp
(
hid int,
greeting varchar(1),
defaultyn int
)
select * from #temp
alter table #temp drop column [$defaultyn]
select * from #temp
...but I cannot get the column to drop if the column has any data in it. I get an error that says "Invalid column name". here's what I'm trying that gives me the error:
Code:
create table #temp
(
hid int,
greeting varchar(1),
defaultyn int
)
insert into #temp
(
hid,
greeting,
defaultyn
)
select
1,
'h',
0
select * from #temp
alter table #temp drop column [$defaultyn]
select * from #temp
Does anyone have any clues on how to drop a temp table column with data in it?
Thanks for your help!!