I am writing a SQL deployment script and I want to check to see if a VIEW exists. If not, then create the view. The logic and code seems pretty straight forward but SQL doesn't like it. The view statement runs fine when run by itself but not inside the if clause. Any assistance would be greatly appreciated.
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'[dbo].[VW_MyViewName]') AND OBJECTPROPERTY(id, N'IsView') = 1)
CREATE VIEW dbo.VW_MyViewName