IF OBJECT_ID('V_PARCIAL_LINHAS') IS NOT NULL 
	DROP VIEW V_PARCIAL_LINHAS
GO

CREATE VIEW V_PARCIAL_LINHAS
AS
SELECT	LINHA.CD_ARV_MERC_LINHA AS CODIGO,LINHA.DS_ARV_MERC_LINHA AS DESCRICAO,COUNT(0) AS QTDE,SUM(TOT_IT) AS TOTAL,ROUND(SUM(TOT_IT) / COUNT(0),2) AS TICKET
FROM	PDV_VD_IT ITEM
INNER	JOIN PDV_VD VD
ON	VD.CD_EMP = ITEM.CD_EMP AND VD.CD_FILIAL = ITEM.CD_FILIAL AND VD.CD_VD = ITEM.CD_VD AND VD.DT_VD = ITEM.DT_VD
INNER	JOIN EST_PROD_EST_ARV_MERCADOLOGICA ARV
ON	ITEM.CD_EMP = ARV.CD_EMP AND ITEM.CD_PROD = ARV.CD_PROD
INNER	JOIN EST_ARV_MERC_LINHA LINHA
ON	ARV.CD_EMP = LINHA.CD_EMP AND ARV.CD_ARV_MERC_LINHA = LINHA.CD_ARV_MERC_LINHA
WHERE	VD.DT_VD = CONVERT(VARCHAR,GETDATE(),112) AND VD.ST_VD = 0 AND ITEM.ST_IT = 1
GROUP	BY LINHA.CD_ARV_MERC_LINHA,LINHA.DS_ARV_MERC_LINHA