alter proc Sp_Summary_of_Top10_Shipments_By_Quantity (@BegDate datetime,@EndDate datetime,@Product varchar(max)) as select distinct T1. C01_CMM_S , T1. c01_GROSS_DATE_T_AS_A_DATE , T1. c01_tkt_in_out_cd_s , T1. c01_tkt_type_s , T1. c01_weight_base_s , T1. c01_shp_to_fr_id_s , T1. C01_LOC_S , T1. NO1_NAM_DESC_1FIELD , T1. C16_CONT_NUM_S , T1. C07_TKT_NUM_S , T1. C01_OTH_REF_NUM_S , T1. C07_CUS_NET_UNTS_D , T1. c16_sch_num_s , T1. EXT_Price , T1. C17_DOC_RMK_S , T1. C16_OTHER_NAM_ID_S , T1. c01_addl_frt_Amt_f Est_Frieght, T1. c16_Other_Prc_F , T2. C05_CMM_DESC_S , T1. c16_Other_Prc_F * T1. C07_CUS_NET_UNTS_D Brokerage, (T1. EXT_Price - T1. c01_addl_frt_Amt_f ) - T1. c16_Other_Prc_F * T1. C07_CUS_NET_UNTS_D Est_Net_rev , case when T1. C01_CMM_S in ('A5', 'B2', 'B5', 'B6', 'D2') then T1. C07_CUS_NET_UNTS_D / 2204.6 when T1. C01_CMM_S in ('G1', 'G3', 'L1', 'N1', 'O1') then T1. C07_CUS_NET_UNTS_D * 1.1023 when T1. C01_CMM_S = 'O2' then T1. C07_CUS_NET_UNTS_D / 2000 else T1. C07_CUS_NET_UNTS_D end ConvertedUnits, T3. N01_NAM_ID_S into #Temp FROM C05_COMMODITY_CODE T2 INNER JOIN trns_Agris_shipment T1 on T1. C01_CMM_S = T2. C05_COMM_CD_S LEFT OUTER JOIN pres_ShipToCust_specie_Salesrep T3 on T1. C01_CMM_S = T3. C01_CMM_S and T1. c01_shp_to_fr_id_s = T3. N01_NAM_ID_S WHERE T1. c01_tkt_in_out_cd_s = 'O' and T1. c01_GROSS_DATE_T_AS_A_DATE between convert(varchar,@BegDate,101) and convert(varchar,@EndDate,101) --{ts '2012-03-01 00:00:00.000'} and {ts '2012-03-30 00:00:00.000'} and T1. c01_tkt_type_s = 'R' and T1. c01_weight_base_s in ('F', 'A') and (t1.C01_CMM_S in (select * from dbo.split(@Product,','))) --and T1. C01_CMM_S in ('C5') order by 1 asc , 9 asc , 10 asc , 13 asc -- select c01_GROSS_DATE_T_AS_A_DATE Date ,NO1_NAM_DESC_1FIELD, EXT_Price , -- case when count(C07_TKT_NUM_S) =1 then Est_Frieght else 0 end EST_Frieght , --Brokerage,C05_CMM_DESC_S, Est_Net_Rev , sum(ConvertedUnits)ConvertedUnits, C05_CMM_DESC_S as Product,convert(varchar,getdate(),101) as Ddate, -- c01_weight_base_s, c01_tkt_in_out_cd_s , c01_tkt_type_s , C07_TKT_NUM_S, -- c01_weight_base_s , c01_shp_to_fr_id_s , C01_OTH_REF_NUM_S , C07_CUS_NET_UNTS_D , c16_sch_num_s -- from #Temp -- group by NO1_NAM_DESC_1FIELD, c01_GROSS_DA
↧
I need help with Rank
↧