mardi 27 janvier 2015

SQL Pivot by data


I have this procedure :



alter proc rel_manipula(@inicio datetime,@fim datetime)
as
select A.codigoins, b.nomeid ,sum(a.qtd), a.dtmov from com_InsusTrans A
inner join com_insus B on b.codigoins = a.codigoins
where (a.dtmov >= @inicio) and (a.dtmov <= @fim)
group by a.codigoins , b.nomeid, a.dtmov
order by a.codigoins


This is the output :



Code Name Total
272 3462090 - (TPT28) 28CM CAB PLASTICO LEITOSO 14098.00
274 3471090 - (TPT30) 30CM CAB PLASTICO LEITOSO 7854.00
289 5731090 - (BTB20) 20CM CAB PLASTICO- LEITOSO 9732.00
292 5732090 - (BPT32) 32CM CAB PLASTICO - LEITOSO 18796.00
303 17591 - (TPT26) 26CM CAB PLASTICO (0 A 24 MESES) 6066.00
516 S 3340010 37735.00
517 S 3340090 1582.00
518 S 3458090 1276.00
519 S 3462090 70.00
520 S 3471090 1141.00
521 S 3486090 1323.00
522 S 5731090 1001.00
524 S 5732090 2973.00
525 S A43 CAPITAL 13035.00
526 S A42 446.00
527 S A40 38.00
528 S L660 788.00
529 S M35 100741.00
532 S A43 FUTURON 2280.00
533 S A43 MONDICAP 152.00
534 S M35G 10226.00


how i need to writ e the pivot to get this output



Data 1 2 3
-------- -----------------------------------------------------
28CM CAB PLASTICO LEITOSO 78 12 210
30CM CAB PLASTICO LEITOSO 90 89 100
20CM CAB PLASTICO- LEITOSO 58 1200 500


where 1 2 3 are days of days of the selected days





Aucun commentaire:

Enregistrer un commentaire