select *
from (
select docdate, cardcode, cardname, case [type]
when 1 then 'cash'
when 2 then 'credit'
when 3 then 'check'
when 4 then 'transfer'
when 5 then 'no doc'
end as PaymentMode, case [type]
when 1 then convert(decimal(20,2), cashsum)
when 2 then creditsum
when 3 then [checksum]
when 4 then trsfrsum
when 5 then nodocsum
end as [Payment Value],
transtype
from tbl T
cross join (
select 1 AS [type] union all select 2 union all
select 3 union all select 4 union all select 5) X
) SQ
where [Payment Value] > 0
order by docdate, cardcode, paymentmode
|