 IF EXISTS
(
    SELECT 1
    FROM SYS.VIEWS
    WHERE NAME = 'V_PRC_SISTEMAS_CTR_VERSAO'
)
    BEGIN
        DROP VIEW V_PRC_SISTEMAS_CTR_VERSAO;
    END;
GO

CREATE VIEW V_PRC_SISTEMAS_CTR_VERSAO AS
	SELECT MAX(VERSAO) AS VERSAO, 'ESTOQUE' as SISTEMA FROM PRC_SISTEMAS_CTR_VERSAO WHERE SISTEMA = 'ESTOQUE'
	UNION ALL
	SELECT MAX(VERSAO) AS VERSAO, 'COMPRAS' as SISTEMA FROM PRC_SISTEMAS_CTR_VERSAO WHERE SISTEMA = 'COMPRAS'
	UNION ALL
	SELECT MAX(VERSAO) AS VERSAO, 'FINANCEIRO' as SISTEMA FROM PRC_SISTEMAS_CTR_VERSAO WHERE SISTEMA = 'FINANCEIRO'
	UNION ALL
	SELECT MAX(VERSAO) AS VERSAO, 'GESTAOCONFIG' as SISTEMA FROM PRC_SISTEMAS_CTR_VERSAO WHERE SISTEMA = 'GESTAOCONFIG'
	UNION ALL
	SELECT MAX(VERSAO) AS VERSAO, 'PDV_NF' as SISTEMA FROM PRC_SISTEMAS_CTR_VERSAO WHERE SISTEMA = 'PDV_NF'
	UNION ALL
	SELECT MAX(VERSAO) AS VERSAO, 'SNGPC' as SISTEMA FROM PRC_SISTEMAS_CTR_VERSAO WHERE SISTEMA = 'SNGPC'
	UNION ALL
	SELECT MAX(VERSAO) AS VERSAO, 'PRECIFICACAO' as SISTEMA FROM PRC_SISTEMAS_CTR_VERSAO WHERE SISTEMA = 'PRECIFICACAO'
	UNION ALL
	SELECT MAX(VERSAO) AS VERSAO, 'CONVENIO' as SISTEMA FROM PRC_SISTEMAS_CTR_VERSAO WHERE SISTEMA = 'CONVENIO'
