-----------------------------------------------------------------------------------------'
--  Script modifica tabelle GT02_CLIENTIFORNITORI, GT09_AGENTI, GT10_AGEMUL, GT14_DESTAGEMUL 
--  campo codice_agente --> nchar(20)
-----------------------------------------------------------------------------------------'

-- GT02_CLIENTIFORNITORI
	if exists (
		select top 1 1
		from  SYSCOLUMNS  with (nolock)
		INNER JOIN SYSOBJECTS  with (nolock) 
			ON SYSOBJECTS.ID = SYSCOLUMNS.ID 
		WHERE SYSCOLUMNS.name = 'GT02_AGENTE_MG17'
			and SYSOBJECTS.NAME = 'GT02_CLIENTIFORNITORI'
			and length = 4
	)
	begin
		alter table GT02_CLIENTIFORNITORI
		alter column GT02_AGENTE_MG17 nchar(20) null

		Print 'Modificata tabella GT02_CLIENTIFORNITORI campo GT02_AGENTE_MG17'
	end 
	GO

-- GT09_AGENTI
	if exists (
		select top 1 1
		from  SYSCOLUMNS  with (nolock)
		INNER JOIN SYSOBJECTS  with (nolock) 
			ON SYSOBJECTS.ID = SYSCOLUMNS.ID 
		WHERE SYSCOLUMNS.name = 'GT09_CODICEGE'
			and SYSOBJECTS.NAME = 'GT09_AGENTI'
			and length = 2
	)
	begin
		alter table GT09_AGENTI
		alter column GT09_CODICEGE nchar(20) null

		Print 'Modificata tabella GT09_AGENTI campo GT09_CODICEGE'
	end 
	GO

	if exists (
		select top 1 1
		from  SYSCOLUMNS  with (nolock)
		INNER JOIN SYSOBJECTS  with (nolock) 
			ON SYSOBJECTS.ID = SYSCOLUMNS.ID 
		WHERE SYSCOLUMNS.name = 'GT09_CAPOAREA'
			and SYSOBJECTS.NAME = 'GT09_AGENTI'
			and length = 2
	)
	begin
		alter table GT09_AGENTI
		alter column GT09_CAPOAREA nchar(20) null

		Print 'Modificata tabella GT09_AGENTI campo GT09_CAPOAREA'
	end 
	GO

	if exists (
		select top 1 1
		from  SYSCOLUMNS  with (nolock)
		INNER JOIN SYSOBJECTS  with (nolock) 
			ON SYSOBJECTS.ID = SYSCOLUMNS.ID 
		WHERE SYSCOLUMNS.name = 'GT09_CAPOZONA'
			and SYSOBJECTS.NAME = 'GT09_AGENTI'
			and length = 2
	)
	begin
		alter table GT09_AGENTI
		alter column GT09_CAPOZONA nchar(20) null

		Print 'Modificata tabella GT09_AGENTI campo GT09_CAPOZONA'
	end 
	GO

	if exists (
		select top 1 1
		from  SYSCOLUMNS  with (nolock)
		INNER JOIN SYSOBJECTS  with (nolock) 
			ON SYSOBJECTS.ID = SYSCOLUMNS.ID 
		WHERE SYSCOLUMNS.name = 'GT09_AGERIF'
			and SYSOBJECTS.NAME = 'GT09_AGENTI'
			and length = 2
	)
	begin
		alter table GT09_AGENTI
		alter column GT09_AGERIF nchar(20) null

		Print 'Modificata tabella GT09_AGENTI campo GT09_AGERIF'
	end 
	GO

-- GT10_AGEMUL
	if exists (
		select top 1 1
		from  SYSCOLUMNS  with (nolock)
		INNER JOIN SYSOBJECTS  with (nolock) 
			ON SYSOBJECTS.ID = SYSCOLUMNS.ID 
		WHERE SYSCOLUMNS.name = 'GT10_CODICEGE'
			and SYSOBJECTS.NAME = 'GT10_AGEMUL'
			and length = 2
	)
	begin
		alter table GT10_AGEMUL
		alter column GT10_CODICEGE nchar(20) null

		Print 'Modificata tabella GT10_AGEMUL campo GT10_CODICEGE'
	end 
	GO

-- GT14_DESTAGEMUL
	if exists (
		select top 1 1
		from  SYSCOLUMNS  with (nolock)
		INNER JOIN SYSOBJECTS  with (nolock) 
			ON SYSOBJECTS.ID = SYSCOLUMNS.ID 
		WHERE SYSCOLUMNS.name = 'GT14_CODICEGE'
			and SYSOBJECTS.NAME = 'GT14_DESTAGEMUL'
			and length = 2
	)
	begin
		alter table GT14_DESTAGEMUL
		alter column GT14_CODICEGE nchar(20) null

		Print 'Modificata tabella GT14_DESTAGEMUL campo GT14_CODICEGE'
	end 
	GO