
DECLARE @SQL nvarchar(4000)
DECLARE @TABLENAME nvarchar(128)
DECLARE @COLUMNNAME nvarchar(128)
DECLARE @COLUMDECLARE  nvarchar(128)

SET @TABLENAME = 'GT06_ARTICOLI'
SET @COLUMNNAME = 'GT06_SOTTOFAM'
SET @COLUMDECLARE = 'char(4) NULL'

IF EXISTS(SELECT top 1 1 FROM master.dbo.sysdatabases WHERE name = 'GETU')
	BEGIN
		IF NOT EXISTS(
			SELECT
				TOP 1 1
			FROM
				getu.sys.SYSCOLUMNS
			INNER JOIN getu.sys.SYSOBJECTS
			ON getu.sys.SYSOBJECTS.ID = getu.sys.SYSCOLUMNS.ID
			WHERE
				getu.sys.SYSCOLUMNS.NAME = @COLUMNNAME
			AND getu.sys.SYSOBJECTS.NAME = @TABLENAME
		)
			BEGIN			
				SET @SQL = '
				ALTER TABLE ' + @TABLENAME + '
				ADD ' + @COLUMNNAME + ' ' + @COLUMDECLARE + ' ' 				
				exec getu.dbo.sp_executesql @SQL
				
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' creato'
				
			END
		ELSE
			BEGIN
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' esistente, creazione non effettuata'
			END			
	END
GO


DECLARE @SQL nvarchar(4000)
DECLARE @TABLENAME nvarchar(128)
DECLARE @COLUMNNAME nvarchar(128)
DECLARE @COLUMDECLARE  nvarchar(128)

SET @TABLENAME = 'GT06_ARTICOLI'
SET @COLUMNNAME = 'GT06_GRUPPO'
SET @COLUMDECLARE = 'char(4) NULL'

IF EXISTS(SELECT top 1 1 FROM master.dbo.sysdatabases WHERE name = 'GETU')
	BEGIN
		IF NOT EXISTS(
			SELECT
				TOP 1 1
			FROM
				getu.sys.SYSCOLUMNS
			INNER JOIN getu.sys.SYSOBJECTS
			ON getu.sys.SYSOBJECTS.ID = getu.sys.SYSCOLUMNS.ID
			WHERE
				getu.sys.SYSCOLUMNS.NAME = @COLUMNNAME
			AND getu.sys.SYSOBJECTS.NAME = @TABLENAME
		)
			BEGIN			
				SET @SQL = '
				ALTER TABLE ' + @TABLENAME + '
				ADD ' + @COLUMNNAME + ' ' + @COLUMDECLARE + ' ' 				
				exec getu.dbo.sp_executesql @SQL
				
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' creato'
				
			END
		ELSE
			BEGIN
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' esistente, creazione non effettuata'
			END			
	END
GO

DECLARE @SQL nvarchar(4000)
DECLARE @TABLENAME nvarchar(128)
DECLARE @COLUMNNAME nvarchar(128)
DECLARE @COLUMDECLARE  nvarchar(128)

SET @TABLENAME = 'GT06_ARTICOLI'
SET @COLUMNNAME = 'GT06_SOTTOGRUPPO'
SET @COLUMDECLARE = 'char(4) NULL'

IF EXISTS(SELECT top 1 1 FROM master.dbo.sysdatabases WHERE name = 'GETU')
	BEGIN
		IF NOT EXISTS(
			SELECT
				TOP 1 1
			FROM
				getu.sys.SYSCOLUMNS
			INNER JOIN getu.sys.SYSOBJECTS
			ON getu.sys.SYSOBJECTS.ID = getu.sys.SYSCOLUMNS.ID
			WHERE
				getu.sys.SYSCOLUMNS.NAME = @COLUMNNAME
			AND getu.sys.SYSOBJECTS.NAME = @TABLENAME
		)
			BEGIN			
				SET @SQL = '
				ALTER TABLE ' + @TABLENAME + '
				ADD ' + @COLUMNNAME + ' ' + @COLUMDECLARE + ' ' 				
				exec getu.dbo.sp_executesql @SQL
				
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' creato'
				
			END
		ELSE
			BEGIN
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' esistente, creazione non effettuata'
			END			
	END
GO

DECLARE @SQL nvarchar(4000)
DECLARE @TABLENAME nvarchar(128)
DECLARE @COLUMNNAME nvarchar(128)
DECLARE @COLUMDECLARE  nvarchar(128)

SET @TABLENAME = 'GT06_ARTICOLI'
SET @COLUMNNAME = 'GT06_GRUPFIS'
SET @COLUMDECLARE = 'char(12) NULL'

IF EXISTS(SELECT top 1 1 FROM master.dbo.sysdatabases WHERE name = 'GETU')
	BEGIN
		IF NOT EXISTS(
			SELECT
				TOP 1 1
			FROM
				getu.sys.SYSCOLUMNS
			INNER JOIN getu.sys.SYSOBJECTS
			ON getu.sys.SYSOBJECTS.ID = getu.sys.SYSCOLUMNS.ID
			WHERE
				getu.sys.SYSCOLUMNS.NAME = @COLUMNNAME
			AND getu.sys.SYSOBJECTS.NAME = @TABLENAME
		)
			BEGIN			
				SET @SQL = '
				ALTER TABLE ' + @TABLENAME + '
				ADD ' + @COLUMNNAME + ' ' + @COLUMDECLARE + ' ' 				
				exec getu.dbo.sp_executesql @SQL
				
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' creato'
				
			END
		ELSE
			BEGIN
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' esistente, creazione non effettuata'
			END			
	END
GO


DECLARE @SQL nvarchar(4000)
DECLARE @TABLENAME nvarchar(128)
DECLARE @COLUMNNAME nvarchar(128)
DECLARE @COLUMDECLARE  nvarchar(128)

SET @TABLENAME = 'GT06_ARTICOLI'
SET @COLUMNNAME = 'GT06_MARCA'
SET @COLUMDECLARE = 'char(12) NULL'

IF EXISTS(SELECT top 1 1 FROM master.dbo.sysdatabases WHERE name = 'GETU')
	BEGIN
		IF NOT EXISTS(
			SELECT
				TOP 1 1
			FROM
				getu.sys.SYSCOLUMNS
			INNER JOIN getu.sys.SYSOBJECTS
			ON getu.sys.SYSOBJECTS.ID = getu.sys.SYSCOLUMNS.ID
			WHERE
				getu.sys.SYSCOLUMNS.NAME = @COLUMNNAME
			AND getu.sys.SYSOBJECTS.NAME = @TABLENAME
		)
			BEGIN			
				SET @SQL = '
				ALTER TABLE ' + @TABLENAME + '
				ADD ' + @COLUMNNAME + ' ' + @COLUMDECLARE + ' ' 				
				exec getu.dbo.sp_executesql @SQL
				
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' creato'
				
			END
		ELSE
			BEGIN
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' esistente, creazione non effettuata'
			END			
	END
GO


DECLARE @SQL nvarchar(4000)
DECLARE @TABLENAME nvarchar(128)
DECLARE @COLUMNNAME nvarchar(128)
DECLARE @COLUMDECLARE  nvarchar(128)

SET @TABLENAME = 'GT06_ARTICOLI'
SET @COLUMNNAME = 'GT06_GRUSTAT1'
SET @COLUMDECLARE = 'char(4) NULL'

IF EXISTS(SELECT top 1 1 FROM master.dbo.sysdatabases WHERE name = 'GETU')
	BEGIN
		IF NOT EXISTS(
			SELECT
				TOP 1 1
			FROM
				getu.sys.SYSCOLUMNS
			INNER JOIN getu.sys.SYSOBJECTS
			ON getu.sys.SYSOBJECTS.ID = getu.sys.SYSCOLUMNS.ID
			WHERE
				getu.sys.SYSCOLUMNS.NAME = @COLUMNNAME
			AND getu.sys.SYSOBJECTS.NAME = @TABLENAME
		)
			BEGIN			
				SET @SQL = '
				ALTER TABLE ' + @TABLENAME + '
				ADD ' + @COLUMNNAME + ' ' + @COLUMDECLARE + ' ' 				
				exec getu.dbo.sp_executesql @SQL
				
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' creato'
				
			END
		ELSE
			BEGIN
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' esistente, creazione non effettuata'
			END			
	END
GO


DECLARE @SQL nvarchar(4000)
DECLARE @TABLENAME nvarchar(128)
DECLARE @COLUMNNAME nvarchar(128)
DECLARE @COLUMDECLARE  nvarchar(128)

SET @TABLENAME = 'GT06_ARTICOLI'
SET @COLUMNNAME = 'GT06_GRUSTAT2'
SET @COLUMDECLARE = 'char(4) NULL'

IF EXISTS(SELECT top 1 1 FROM master.dbo.sysdatabases WHERE name = 'GETU')
	BEGIN
		IF NOT EXISTS(
			SELECT
				TOP 1 1
			FROM
				getu.sys.SYSCOLUMNS
			INNER JOIN getu.sys.SYSOBJECTS
			ON getu.sys.SYSOBJECTS.ID = getu.sys.SYSCOLUMNS.ID
			WHERE
				getu.sys.SYSCOLUMNS.NAME = @COLUMNNAME
			AND getu.sys.SYSOBJECTS.NAME = @TABLENAME
		)
			BEGIN			
				SET @SQL = '
				ALTER TABLE ' + @TABLENAME + '
				ADD ' + @COLUMNNAME + ' ' + @COLUMDECLARE + ' ' 				
				exec getu.dbo.sp_executesql @SQL
				
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' creato'
				
			END
		ELSE
			BEGIN
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' esistente, creazione non effettuata'
			END			
	END
GO

DECLARE @SQL nvarchar(4000)
DECLARE @TABLENAME nvarchar(128)
DECLARE @COLUMNNAME nvarchar(128)
DECLARE @COLUMDECLARE  nvarchar(128)

SET @TABLENAME = 'GT06_ARTICOLI'
SET @COLUMNNAME = 'GT06_GRUSTAT3'
SET @COLUMDECLARE = 'char(4) NULL'

IF EXISTS(SELECT top 1 1 FROM master.dbo.sysdatabases WHERE name = 'GETU')
	BEGIN
		IF NOT EXISTS(
			SELECT
				TOP 1 1
			FROM
				getu.sys.SYSCOLUMNS
			INNER JOIN getu.sys.SYSOBJECTS
			ON getu.sys.SYSOBJECTS.ID = getu.sys.SYSCOLUMNS.ID
			WHERE
				getu.sys.SYSCOLUMNS.NAME = @COLUMNNAME
			AND getu.sys.SYSOBJECTS.NAME = @TABLENAME
		)
			BEGIN			
				SET @SQL = '
				ALTER TABLE ' + @TABLENAME + '
				ADD ' + @COLUMNNAME + ' ' + @COLUMDECLARE + ' ' 				
				exec getu.dbo.sp_executesql @SQL
				
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' creato'
				
			END
		ELSE
			BEGIN
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' esistente, creazione non effettuata'
			END			
	END
GO


DECLARE @SQL nvarchar(4000)
DECLARE @TABLENAME nvarchar(128)
DECLARE @COLUMNNAME nvarchar(128)
DECLARE @COLUMDECLARE  nvarchar(128)

SET @TABLENAME = 'GT06_ARTICOLI'
SET @COLUMNNAME = 'GT06_GRUSTAT4'
SET @COLUMDECLARE = 'char(4) NULL'

IF EXISTS(SELECT top 1 1 FROM master.dbo.sysdatabases WHERE name = 'GETU')
	BEGIN
		IF NOT EXISTS(
			SELECT
				TOP 1 1
			FROM
				getu.sys.SYSCOLUMNS
			INNER JOIN getu.sys.SYSOBJECTS
			ON getu.sys.SYSOBJECTS.ID = getu.sys.SYSCOLUMNS.ID
			WHERE
				getu.sys.SYSCOLUMNS.NAME = @COLUMNNAME
			AND getu.sys.SYSOBJECTS.NAME = @TABLENAME
		)
			BEGIN			
				SET @SQL = '
				ALTER TABLE ' + @TABLENAME + '
				ADD ' + @COLUMNNAME + ' ' + @COLUMDECLARE + ' ' 				
				exec getu.dbo.sp_executesql @SQL
				
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' creato'
				
			END
		ELSE
			BEGIN
				PRINT 'Tabella ' + @TABLENAME + ': campo ' + @COLUMNNAME + ' esistente, creazione non effettuata'
			END			
	END
GO
