DECLARE @SQL VARCHAR(1000)

IF EXISTS
	(
	  SELECT SysColumns.Name 
	  FROM SysObjects WITH (NOLOCK) 
		INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
		AND SysColumns.Name = 'CompanyForm'
		WHERE SysObjects.Name = 'Customer' AND syscolumns.iscomputed = 1
	)
		ALTER TABLE dbo.Customer DROP COLUMN CompanyForm

IF EXISTS (
SELECT * FROM sysobjects 
WHERE name = 'GetDefaultEAN' and xtype = 'FN'
)

	


	SET @SQL = 'ALTER FUNCTION [dbo].[GetDefaultEAN] (@ACustomerNumber int) RETURNS varchar(20)
				AS
				BEGIN
					DECLARE @ResultVar varchar(29)

					SELECT @ResultVar = EAN FROM CustomerEANs (NOLOCK)
					WHERE CustomerNumber = @ACustomerNumber AND EANType = 0
	
					RETURN @ResultVar
				END'

ELSE
	SET @SQL = 'CREATE FUNCTION [dbo].[GetDefaultEAN] (@ACustomerNumber int) RETURNS varchar(20)
				AS
				BEGIN
					DECLARE @ResultVar varchar(29)

					SELECT @ResultVar = EAN FROM CustomerEANs (NOLOCK)
					WHERE CustomerNumber = @ACustomerNumber AND EANType = 0
	
					RETURN @ResultVar
				END'

EXEC (@SQL)