PIVOT and sum two columns -


i hope formulated ddl +dml query , question without mistakes.

i build query

declare @temp tehoodotrechesh (       vendorcode int     , vendorname nvarchar(50)     , checkdate datetime     , checksum decimal(10,2)     , objtype int )  insert @temp tehoodotrechesh (vendorcode, vendorname, checkdate, checksum,objtype values      (1, 'aaa', '20130101', 40,18),     (1, 'aaa', '20130101', 60,18),     (1, 'aaa', '20130101', 40,19),     (2, 'bbb', '20130303', 50,18),     (2, 'bbb', '20130601', 10,18),     (2, 'bbb', '20130604', 20,19)   select *  ( select  case when [objtype]='18' n'tr' else n'tz' end 'dt',   cardcode,  cardname, year(docduedate) 'year',left(datename(month,docduedate),3) [month],  doctotal 'amount' tehoodorrechesh docstatus ='o' ) monthsum pivot  ( sum (amount) [month] in (jan, feb, mar, apr, may, jun, jul, aug, sep, oct,  nov, dec) ) sumpivot 

  1. i want sum rows of documets objtype 18 / 19 (only 2 types) , sum objtype months.
  2. is there oportunity if objtype 19 put numbers minus opertaor (-) or in brackets ()
  3. when wrote order vendor code works, if add order by: vendorcode + objtype not working. why?


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -