IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[VGT_DESTINATARI]'))
DROP VIEW [dbo].[VGT_DESTINATARI]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO

CREATE VIEW [dbo].[VGT_DESTINATARI]
AS
	select *
	, (SELECT TOP 1 GT02_CODICEGE 
		FROM GT02_CLIENTIFORNITORI
		WHERE GT02_ID = [GT13_ID_GT02]) AS [GT13_CLIFOR_GE]
	, (SELECT TOP 1 GT02_IND_TIPO_CLIENTE_FORNITORE 
		FROM GT02_CLIENTIFORNITORI
		WHERE GT02_ID = [GT13_ID_GT02]) AS [GT13_INDTIPOCF_GE]		 
	from GT13_DESTINATARI
	WHERE GT13_SYNCGE = 1
	AND GT13_CODICEGE IS NULL
