Stored procedures 将sql查询转换为存储过程

Stored procedures 将sql查询转换为存储过程,stored-procedures,Stored Procedures,将sql查询包装在 创建过程进程名 像 这里有疑问 去 有关更多详细信息,请参阅将其粘贴到存储过程中的哪一部分会让您感到不安?我想CREATE procedure命令的语法和示例可以在Google上轻松找到。你被困在哪里?你试过什么不起作用的?可能是重复的 Select OpportunityId from opportunity AS c left JOIN ( select a.opportunitynameid from opportunity

将sql查询包装在 创建过程进程名 像 这里有疑问 去
有关更多详细信息,请参阅将其粘贴到存储过程中的哪一部分会让您感到不安?我想CREATE procedure命令的语法和示例可以在Google上轻松找到。你被困在哪里?你试过什么不起作用的?可能是重复的
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
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