-----------------------------------------------------------------------------------------'
-- Mofica campi per codice cliente/fornitore a decimal(8,0)											 
-----------------------------------------------------------------------------------------'

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


-- GT03_DOCTESTATA
	IF EXISTS(
		SELECT
			TOP 1 1
		FROM
			SYSCOLUMNS
		INNER JOIN SYSOBJECTS
		ON SYSOBJECTS.ID = SYSCOLUMNS.ID
		WHERE
			SYSCOLUMNS.NAME = 'GT03_CLIFOR'
		AND SYSOBJECTS.NAME = 'GT03_DOCTESTATA'
		AND SYSCOLUMNS.xtype = 106
		AND xprec = 6
	)
		BEGIN
		   ALTER TABLE GT03_DOCTESTATA

			ALTER COLUMN GT03_CLIFOR decimal(8,0) NULL
		
		   PRINT 'Tabella GT03_DOCTESTATA: campo GT03_CLIFOR modificato'

		END
	GO

-- GT10_AGEMUL
	IF EXISTS(
		SELECT
			TOP 1 1
		FROM
			SYSCOLUMNS
		INNER JOIN SYSOBJECTS
		ON SYSOBJECTS.ID = SYSCOLUMNS.ID
		WHERE
			SYSCOLUMNS.NAME = 'GT10_CLIFOR'
		AND SYSOBJECTS.NAME = 'GT10_AGEMUL'
		AND SYSCOLUMNS.xtype = 106
		AND xprec = 6
	)
		BEGIN
		   ALTER TABLE GT10_AGEMUL

			ALTER COLUMN GT10_CLIFOR decimal(8,0) NULL
		
		   PRINT 'Tabella GT10_AGEMUL: campo GT10_CLIFOR modificato'

		END
	GO

-- GT13_DESTINATARI
	IF EXISTS(
		SELECT
			TOP 1 1
		FROM
			SYSCOLUMNS
		INNER JOIN SYSOBJECTS
		ON SYSOBJECTS.ID = SYSCOLUMNS.ID
		WHERE
			SYSCOLUMNS.NAME = 'GT13_CLIFOR'
		AND SYSOBJECTS.NAME = 'GT13_DESTINATARI'
		AND SYSCOLUMNS.xtype = 106
		AND xprec = 6
	)
		BEGIN
		   ALTER TABLE GT13_DESTINATARI

			ALTER COLUMN GT13_CLIFOR decimal(8,0) NULL
		
		   PRINT 'Tabella GT13_DESTINATARI: campo GT13_CLIFOR modificato'

		END
	GO

-- GT14_DESTAGEMUL
	IF EXISTS(
		SELECT
			TOP 1 1
		FROM
			SYSCOLUMNS
		INNER JOIN SYSOBJECTS
		ON SYSOBJECTS.ID = SYSCOLUMNS.ID
		WHERE
			SYSCOLUMNS.NAME = 'GT14_CLIFOR'
		AND SYSOBJECTS.NAME = 'GT14_DESTAGEMUL'
		AND SYSCOLUMNS.xtype = 106
		AND xprec = 6
	)
		BEGIN
		   ALTER TABLE GT14_DESTAGEMUL

			ALTER COLUMN GT14_CLIFOR decimal(8,0) NULL
		
		   PRINT 'Tabella GT14_DESTAGEMUL: campo GT14_CLIFOR modificato'

		END
	GO

-- GT05_GEDATICLIFOR
	IF EXISTS(
		SELECT
			TOP 1 1
		FROM
			SYSCOLUMNS
		INNER JOIN SYSOBJECTS
		ON SYSOBJECTS.ID = SYSCOLUMNS.ID
		WHERE
			SYSCOLUMNS.NAME = 'GT05_CODICEGE'
		AND SYSOBJECTS.NAME = 'GT05_GEDATICLIFOR'
		AND SYSCOLUMNS.xtype = 106
		AND xprec = 6
	)
		BEGIN
			IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[GT05_GEDATICLIFOR]') AND name = N'IDX02_GT05')
			DROP INDEX [GT05_GEDATICLIFOR].[IDX02_GT05]

			ALTER TABLE GT05_GEDATICLIFOR
			ALTER COLUMN GT05_CODICEGE decimal(8,0) NULL
			PRINT 'Tabella GT05_GEDATICLIFOR: campo GT05_CODICEGE modificato'

			CREATE UNIQUE NONCLUSTERED INDEX [IDX02_GT05] ON [dbo].[GT05_GEDATICLIFOR]
			(
				[GT05_CODICEGE] ASC,
				[GT05_DITTA] ASC
			)
		END
	GO