Rename the table Column
Posted
by Harendra
on Stack Overflow
See other posts from Stack Overflow
or by Harendra
Published on 2010-05-08T09:23:49Z
Indexed on
2010/05/08
9:28 UTC
Read the original article
Hit count: 162
Hi all, I am trying to execute the following query. I don't have 'CrewID' column so in that case it will by pass update part of the script. but it gives error Invalid object CrewID'. Can you please tell me why it excute update part even my if condition does not matched. Is there is another way to do the same. I have the requirement where need to rename the column but before rename i have to copied data in other column and need to excute script many times.
if exists (select * from syscolumns where name ='CrewID' and id in (select id from dbo.sysobjects where id = object_id(N'[dbo].[WorkPlanAssignees]') and OBJECTPROPERTY(id, N'IsUserTable') = 1))
BEGIN
update A set A.TempCrewID=B.ID from WorkPlanAssignees A inner join Crew B on A.CrewID=B.ID
END
© Stack Overflow or respective owner