error varchar(20),i1.incdate,121)+convert(varchar(20),i1.inctime,121)
as id,i1.hn,i1.rcpno,i1. at line 1
select distinct(i1.hn+convert(varchar(20),i1.incdate,121)+convert(varchar(20),i1.inctime,121))
as id,i1.hn,i1.rcpno,i1.incdate,
rtrim(rtrim(pt.pname)+rtrim(pt.fname)+" "+rtrim(pt.lname)) as ptname,
(select sum(rcptamt) from incoth where hn=i1.hn and incdate=i1.incdate and inctime=i1.inctime and paidst="00") as money0,
(select sum(rcptamt) from incoth where hn=i1.hn and incdate=i1.incdate and inctime=i1.inctime and paidst="01") as money1,
(select sum(rcptamt) from incoth where hn=i1.hn and incdate=i1.incdate and inctime=i1.inctime and paidst="02") as money2,
(select sum(rcptamt) from incoth where hn=i1.hn and incdate=i1.incdate and inctime=i1.inctime ) as totmoney
from incoth i1
left outer join patient pt on pt.hn=i1.hn
where convert(char(7),i1.incdate,121)="2011-08" and rtrim(i1.rcpno) <> ""
group by i1.hn,i1.incdate,i1.inctime,i1.paidst,i1.rcpno,pt.pname,pt.fname,pt.lname
order by i1.rcpno,i1.incdate,i1.hn
รบกวนตรวจสอบให้ด้วยครับ ขอบคุณครับ