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