Ajax (1) Apex Class (12) Apex Trigger (2) Community (2) Home Page (1) HTML (4) Integration (3) JS (7) KB (1) Label (1) Licenses (1) Listing (1) Log (1) OOPs (5) Sharing (1) Static Resource (1) Test Class (3) URI (1) Visualforce (10)

Monday 16 June 2014

sql procedure

/*Procedure*/
ALTER PROC sp_TUI
@pkg_Code VARCHAR(20),
@bid int,
@p_name VARCHAR(20)
AS
BEGIN
SET @pkg_Code=REPLACE(@pkg_Code,'null','')
SET @p_name=REPLACE(@p_name,'null','')
SELECT b_id 'Booking Reference',title 'Lead Pax Title',first_name 'Lead Pax 1st Name',last_name 'Lead Pax 2nd Name',age 'Lead Pax Age',a_code 'Agent Code',
a_name 'Agent name',branch_code 'Branch Code',region_code 'Region Code',Channel,p_Code 'Product Code',b_Type 'Booking Type',p_Type 'Product Type',
pkg_Code 'Package Code',pkg_Name 'Package Name',b_Booking_Date 'Booking Date',b_Dep_Date 'Departure Date',b_No_of_Adults 'No of Adults',
b_No_of_Childs 'No of Childs',b_No_of_Infants 'No of Infants',outbond_dep_airport 'Outbound Departure Airport',outbond_Arrival_airport 'Outbound Arrival Airport',
inbond_dep_airport 'Inbound Departure Airport',inbond_Arrival_airport 'Inbound Arrival Airport',S_Type 'Service Type',s_Code 'Service Code',s_name 'Service Name',S_Dep 'Service Departure',
S_Arr 'Service Arrival',S_Cost 'Service Cost',S_Sale_price 'Service Sale Price',S_Margin 'Service Margin',S_Margin_percent 'Service Marging %',total_booking_cost 'Total Booking Cost',
booking_margin 'Booking Margin',booking_marging_percent 'Booking margin %',p_Name 'Product name',mobile 'Opp Mobile',email 'Opp Email',
booking_confirmed,
pli_days 'Day'
FROM Booking   
JOIN Product  ON Booking.p_id_r=Product.p_id  
JOIN Opportunity ON Booking.opp_id_r=Opportunity.opp_id
JOIN Package  ON Booking.pkg_id=Package.pkg_id  
JOIN TUI_Service ON Booking.b_id=TUI_Service.b_id_r
JOIN Package_Line_Item ON TUI_Service.pkg_line_item_id_r=Package_Line_Item.pkg_line_item_id
JOIN Agent  ON Booking.a_id_r=Agent.a_id

where (pkg_Code=@pkg_Code OR ISNULL(@pkg_Code,'')='')
AND (p_Name=@p_name OR ISNULL(@p_name,'')='')
AND CASE WHEN @bid != 0
    THEN
        b_id
    ELSE
        @bid
    END
    =
    CASE WHEN @bid != 0
    THEN
        @bid
    ELSE
        @bid
    END

--GROUP BY p_Name, pkg_Name, b_id
ORDER BY p_Name, pkg_Name, b_id

END

--exec sp_TUI NULL,14,Null


No comments:

Post a Comment