将sql查询转换为存储过程

时间:2016-03-16 13:06:28

标签: stored-procedures

Select OpportunityId 
from opportunity AS c 
    left JOIN (
        select a.opportunitynameid 
        from opportunity o
            JOIN ApprovalDocument a ON a.opportunitynameid=o.OpportunityId
    ) AS b ON c.OpportunityId=b.opportunitynameid
Where b.opportunitynameid IS NULL and statecode=0

2 个答案:

答案 0 :(得分:0)

Create Procedure mySP_GetOpportunity
@statuscode int = 0
As
Select OpportunityId 
from opportunity AS c left JOIN 
    ( select a.opportunitynameid from opportunity o JOIN ApprovalDocument a ON a.opportunitynameid=o.OpportunityId ) AS b 
    ON c.OpportunityId=b.opportunitynameid 
Where b.opportunitynameid IS NULL 
and statecode=@statuscode

答案 1 :(得分:0)

CREATE PROCEDURE Proc_Name AS "query goes here" GO 之间包装sql查询 有关详细信息,请参阅this