| Author |
Topic |
|
madhuri99m
Starting Member
1 Post |
Posted - 2011-03-24 : 16:16:46
|
| I have my table with these columnsInvoiceNO,order date,orderid,orderQTY,Price20001205BRT 2011-03-22 200510255 1 14.0020006505BRT 2011-03-22 200510255 1 8.9820006505WRX 2011-03-22 200510256 3 14.0022891235DFG 2011-03-22 200510256 3 12.9822896505TCP 2011-03-22 200510256 3 14.002289ERTY104 2011-03-22 200510256 2 8.982289JPMW786 2011-03-22 200510256 3 14.002289KLWSQ18 2011-03-22 200510256 3 14.00228M23YHNPF 2011-03-22 200510256 5 14.00228MRGH23MP 2011-03-22 200510256 5 14.00228MRGRTPSD 2011-03-22 200510256 5 14.00228MRTP3858 2011-03-22 200510256 1 14.00i have to write a query so that under each invoice it has to show total record by calculating (orderQty*price). I have to display IT for each item record and TT for total records and add all the column values . For example take the 3rd row from my tablethe details record should be like thisIT20006505WRX2011-03-22200510256314.00TT20006505WRX2011-03-22200510256342.00 --This is total record where the price is (3*14=42)I have to repeat this for all the records. I have to show IT(which is first then below that I have to show TTrecord |
|
|
pduffin
Yak Posting Veteran
68 Posts |
Posted - 2011-03-24 : 19:03:27
|
| select '20001205BRT' as InvoiceNO, cast('2011-03-22' as datetime) as [order date], '200510255' as orderid, 1 as orderQTY, 14.00 as Priceinto #tmppmdinsert into #tmppmd values ('20006505BRT', '2011-03-22' , '200510255', 1 ,8.98)insert into #tmppmd values ('20006505WRX', '2011-03-22' , '200510256', 3 ,14.00)insert into #tmppmd values ('22891235DFG', '2011-03-22' , '200510256', 3 ,12.98)insert into #tmppmd values ('22896505TCP', '2011-03-22' , '200510256', 3 ,14.00)insert into #tmppmd values ('2289ERTY104', '2011-03-22' , '200510256', 2 ,8.98)insert into #tmppmd values ('2289JPMW786', '2011-03-22' , '200510256', 3 ,14.00)insert into #tmppmd values ('2289KLWSQ18', '2011-03-22' , '200510256', 3 ,14.00)insert into #tmppmd values ('228M23YHNPF', '2011-03-22' , '200510256', 5 ,14.00)insert into #tmppmd values ('228MRGH23MP', '2011-03-22' , '200510256', 5 ,14.00)insert into #tmppmd values ('228MRGRTPSD', '2011-03-22' , '200510256', 5 ,14.00)insert into #tmppmd values ('228MRTP3858', '2011-03-22' , '200510256', 1 ,14.00)select *from( select 'IT' as Type,* from #tmppmd pmd union all select 'TT', invoiceno,[order date],orderid,orderqty,orderqty*price from #tmppmd pmd) aorder by invoiceno, type |
 |
|
|
|
|
|