How to convert this sql statement to storeproc?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anand000925
    New Member
    • Oct 2014
    • 1

    How to convert this sql statement to storeproc?

    How to convert this sql statement to storeproc?
    Code:
    select	"Dly_DC_LostSlsSnpsht_v"."PlntCd" "Plnt_Id_Cd" , "Dly_DC_LostSlsSnpsht_v"."DivCd" "Div_Cd" ,
    		"GlblCatSum"."GlblCatSumCd" "Gbl_Cat_Sum_Cd" , (coalesce("GlblCatSum"."GlblCatSumDesc",
    		'Unknow')) "Gbl_Cat_Sum_Desc" , "Dly_DC_LostSlsSnpsht_v"."ProdtCd" "Prod_Cd" ,
    		"ProdtGPI"."ProdtLglLongNm" "Matl_Nm" , "Dly_DC_LostSlsSnpsht_v"."WhlslPrcAmt_USD" "Whlsl_Prc__USD_" ,
    		sum("Dly_DC_LostSlsSnpsht_v"."EstdLostSlsQty") "Estd_Lost_Sales_Qty" ,
    		sum("Dly_DC_LostSlsSnpsht_v"."EstdLostSlsAmt") "Estd_Lost_Sales_Amt" ,
    		sum("Dly_DC_LostSlsSnpsht_v"."EstdDmndQty") "Tot_AO_Dmd_Qty" ,
    		(sum("Dly_DC_LostSlsSnpsht_v"."EstdLostSlsQty") * 1.0e0) / (NULLIF(sum("Dly_DC_LostSlsSnpsht_v"."EstdDmndQty"),
    		0)) "Estd_Lost_Sales__" 
     from "EIS"."Dly_DC_LostSlsSnpsht_v" "Dly_DC_LostSlsSnpsht_v",
    		"EIS"."GlblCatSum" "GlblCatSum", "EIS"."ProdtGPI" "ProdtGPI",
    		"EIS"."GlblCatCoreFcs" "GlblCatCoreFcs"
     where "Dly_DC_LostSlsSnpsht_v"."CalRunDt" between date - 1 
    	and	date 
    	and	"Dly_DC_LostSlsSnpsht_v"."ProdtCd" = "ProdtGPI"."ProdtCd" 
    	and	"GlblCatCoreFcs"."GlblCatCoreFcsCd" = "ProdtGPI"."GlblCatCoreFcsCd" 
    	and	"GlblCatSum"."GlblCatSumCd" = "GlblCatCoreFcs"."GlblCatSumCd"
     group by "Dly_DC_LostSlsSnpsht_v"."PlntCd", "Dly_DC_LostSlsSnpsht_v"."DivCd", "GlblCatSum"."GlblCatSumCd", (coalesce("GlblCatSum"."GlblCatSumDesc", 'Unknow')), "Dly_DC_LostSlsSnpsht_v"."ProdtCd", "ProdtGPI"."ProdtLglLongNm", "Dly_DC_LostSlsSnpsht_v"."WhlslPrcAmt_USD"
    Last edited by Frinavale; Oct 27 '14, 01:46 PM. Reason: Added the question asked in the title of the thread to the body of the thread so that the code posted has context. Also added code tags around code.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Use the CREATE PROCEDURE to create a stored procedure with a name and parameters. Add the SQL command that you posted within the procedure...

    For more information about how to create a stored procedure checkout this MSDN Documentation on the CREATE PROCEDURE (Transact-SQL), and this overview on how to Create a Stored Procedure and this documentation on how to Execute a Stored Procedure.

    -Frinny

    Comment

    Working...