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

SET @TABLENAME = 'GT02_CLIENTIFORNITORI'
SET @COLUMNNAME = 'GT02_REGIONE'
SET @COLUMDECLARE = 'varchar(1) 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 = 'GT02_CLIENTIFORNITORI'
SET @COLUMNNAME = 'GT02_MACROCAT'
SET @COLUMDECLARE = 'char(3) 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 = 'GT02_CLIENTIFORNITORI'
SET @COLUMNNAME = 'GT02_CATEG'
SET @COLUMDECLARE = 'char(3) 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 = 'GT02_CLIENTIFORNITORI'
SET @COLUMNNAME = 'GT02_SOTTOCAT'
SET @COLUMDECLARE = 'char(3) 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 = 'GT02_CLIENTIFORNITORI'
SET @COLUMNNAME = 'GT02_RAGGRCF1'
SET @COLUMDECLARE = 'char(3) 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 = 'GT02_CLIENTIFORNITORI'
SET @COLUMNNAME = 'GT02_RAGGRCF2'
SET @COLUMDECLARE = 'char(3) 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 = 'GT02_CLIENTIFORNITORI'
SET @COLUMNNAME = 'GT02_RAGGRCF3'
SET @COLUMDECLARE = 'char(3) 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
