if((select Default_Value from System_Default where Default_Name ='ISJV') =1) begin DROP VIEW [dbo].[vwGetConsumables] SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON exec ( 'CREATE VIEW [dbo].[vwGetConsumables] AS SELECT p.Product_ID, v.Division, v.Category, p.Product_Code, p.Description, h.Current_Cost, h.Current_Stock, 0 as OrderQuantity FROM dbo.Product AS p LEFT OUTER JOIN dbo.vwProductCategory AS v ON p.Product_Category_ID = v.Product_Category_ID LEFT OUTER JOIN dbo.HQ_Product_Stock AS h ON h.Product_ID = p.Product_ID WHERE v.Division = ''Expenses'' and h.HQ_Branch_ID in (select top(1) CAST(Default_Value AS int) from System_Default where Default_Name = ''HQ_Store_Branch'')') end;