You are on page 1of 2

USE [SA_Live] GO /****** Object: StoredProcedure [dbo].

[SP_GET_SWFloating_report_Listed_Bulding] Script Date: 09/05/2013 13:58:50 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[SP_GET_SWFloating_report_Listed_Bulding] (@status varchar(100) , @type_id varchar(100) , @affiliate varchar(100)) AS BEGIN SET NOCOUNT ON SET XACT_ABORT ON BEGIN TRAN SELECT A.name AS Agent, AF.code As Affiliate, CC.surname as ClientFamilyName, CC.lastname as ClientFirstName, C.internal_ref_no as IntRefNo, C.external_ref_no, cs.name as Status, P.code as Project, m.name as EventType, ot.name As OrderType ,C.purchased_qty as SumFCOrder, C.contract_sum as SumOfForcast, ct.gift_list, cp.riv_projects as riv_projectcode,

A.name AS Agent, AF.code As Affiliate, CC.surname as ClientFamilyName, CC.lastname as ClientFirstName, C.internal_ref_no as IntRefNo, C.external_ref_no, cs.name as Status, P.code as Project, m.name as EventType, ot.name As OrderType ,C.purchased_qty as SumFCOrder ,mp.name as category ,mc.currency_code as CurrencyCode, C.contract_sum as ContractSUM, c.gross_contract_value as grosscontractsum, ct.gift_list, cp.riv_projects as riv_projectcode, c.status, cs.name FROM CONTRACT C join AGENT A on C.sales_agent_id=A.agent_id join affiliate AF on A.affiliate_id=AF.affiliate_id join contract_client CC on CC.contract_id=C.contract_id and cc.status =1 and cc.main_applicant =1 join Project P on C.project_id = P.project_id join event E on C.event_id= E.event_id

join map_event_type m on E.event_type = m.map_event_type_id join map_sales_order_type ot on c.order_type = ot.map_sales_order_type_id join map_contract_status cs on cs.map_contract_status = c.status join map_currency mc on mc.map_currency_id = p.currency join map_project_type mp on mp.map_project_type_id = p.type left join (Select distinct ST2.contract_id, substring((Select ','+ cast(st1.quantity as varchar) +'x'+ g.name AS [text()] From dbo.contract_gift ST1 , dbo.gift g Where ST1.contract_id = ST2.contract_id and st1.gift_id = g.gift _id and st1.status = 1 ORDER BY ST1.contract_id For XML PATH ('')),2, 1000) [gift_list] From dbo.contract_gift ST2) ct on ct.contract_id = c.contract_id left join (Select distinct ST2.contract_id, substring((Select ','+ p.code +'('+ ct.internal_ref_no +')' AS [ text()] From dbo.contract_payment ST1, contract ct , project p Where ST1.contract_id = ST2.contract_id and st1.status =1 and st1.payment_type=2 and st1.payment_reference=ct.internal_ref_n o and ct.project_id =p.project_id ORDER BY ST1.contract_id For XML PATH ('')),2, 1000) [riv_projects] From dbo.contract_payment ST2 where st2.payment_type = 2) cp on cp.cont ract_id=c.contract_id WHERE C.status IN(select * from dbo.Split(@status, ',')) AND (P.type IN (select * from dbo.Split(@type_id, ',')) OR ( @type_id ='0' ) ) AND (AF.affiliate_id IN (select * from dbo.Split(@affiliate, ',')) OR ( @affil iate ='0' )) order by agent Commit END

You might also like