Query’s não comtemplam estabelecimentos, nesse caso no código do cliente terá de acrescentar á query.
Query para o ecrã de quantidades:
select top 25 pn.ref as 'Referência', st.design as 'Designação', sum(Case when convert(char(8),pn.fdata,112) >= ltrim(rtrim(str(year(getdate())-1)))+right('00'+ltrim(rtrim(str(month(getdate())))),2)+'01' then pn.qtt else 0 end) as 'Quantidade', convert(decimal(16,3), sum(Case when convert(char(8),pn.fdata,112) >= ltrim(rtrim(str(year(getdate())-1)))+right('00'+ltrim(rtrim(str(month(getdate())))),2)+'01' then pn.ETILIQUIDO else 0 end)) as 'Valor em Euros' from pn (nolock) inner join st (nolock) on st.ref=pn.ref where convert(char(8),pn.fdata,112) >= ltrim(rtrim(str(year(getdate())-2)))+right('00'+ltrim(rtrim(str(month(getdate())))),2)+'01' and cast(pn.no as varchar)='[DCCCLI]' group by pn.ref,st.design order by 3 desc
Query para o ecrã de consultas:
select top 25 pn.ref as 'Referência', st.design as 'Designação', sum(Case when convert(char(8),pn.fdata,112) >= ltrim(rtrim(str(year(getdate())-1)))+right('00'+ltrim(rtrim(str(month(getdate())))),2)+'01' then pn.qtt else 0 end) as 'Quantidade', convert(decimal(16,3), sum(Case when convert(char(8),pn.fdata,112) >= ltrim(rtrim(str(year(getdate())-1)))+right('00'+ltrim(rtrim(str(month(getdate())))),2)+'01' then pn.ETILIQUIDO else 0 end)) as 'Valor em Euros' from pn (nolock) inner join st (nolock) on st.ref=pn.ref where convert(char(8),pn.fdata,112) >= ltrim(rtrim(str(year(getdate())-2)))+right('00'+ltrim(rtrim(str(month(getdate())))),2)+'01' and cast(pn.no as varchar)='[<MSCLI>Qual o Cliente]' group by pn.ref,st.design order by 3 desc