Question : sql query help.

hi all,

i have a query

select convert(varchar,docdate,101) docdate,cardcode,cardname,cashacct,cashsum,creditsum,checkacct,checksum,trsfrsum,paynodoc,nodocsum,doctotal,
(case when jdt.transtype = '24' then 'Incoming Payment' else '' end) as transtype
,cntctcode from orct oct inner join ojdt jdt
on oct.transid = jdt.transid
where oct.docdate between '07/01/2010' and '07/27/2010'

i am getting the results. but i am trying to make an output in a different way.

i am attaching an excel sheet. i have 2 sheets. sheet1 actual data i get from the query but i want the output like sheet2.
Attachments:
 
final result
 

Answer : sql query help.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
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
Random Solutions  
 
programming4us programming4us