Declare @nome as Char(50)
Set @nome= '#3#'
select fc.fcstamp as stamp,
case when fc.estab>0 then ltrim(rtrim(fc.nome))+' - '+convert(varchar(10),fc.no)
+' - '+convert(varchar(10),fc.estab)
else fc.nome+ ' - ' +convert(varchar(10),fc.no) end as nome,
rtrim(fc.cmdesc)+' '+CAST(fc.Adoc AS VARCHAR (10)) as documento,
fc.datalc as data, fc.dataven as dataven,
(fc.ecred-fc.edeb) as original,
((fc.ecred-fc.ecredf)-(fc.edeb-fc.edebf)) as saldo,
datediff(dd,fc.dataven,getdate())as dias,
CASE WHEN dataven>GETDATE() THEN 'Por Vencer' else
case when cast(dataven as DATE)=CAST(getdate()as DATE) then 'Próprio Dia' else
case WHEN dataven<GETDATE() THEN 'Vencida' end end
END as estado
from fc(nolock)
where (fc.origem='FO' or fc.origem='FC' or ('#4#' = '1' and fc.origem='PD')) and
((fc.ecred-fc.ecredf)-(fc.edeb-fc.edebf))<>'0'
and fc.datalc>='#1#' and fc.datalc<='#2#'
and ('#3#' = 'Todos os Fornecedores' or ( '#3#' <> 'Todos os Fornecedores' and
fc.nome=@nome))
order by nome, dataven asc, data asc