如何使用模式绑定创建存储过程?

Sam*_*ack 4 sql t-sql sql-server stored-procedures sql-server-2008

我正在尝试使用模式绑定创建存储过程,但我无法这样做。

错误:

为语句“CREATE/ALTER PROCEDURE”指定了无效选项

甚至可以使用模式绑定创建存储过程吗?

create procedure dbo.proc_GetIncome  (
@fromdate datetime,  
@todate datetime  )
with schemabinding
as  
begin
declare @from varchar(8)  
declare @to varchar(8)  

select @from = YEAR(@fromdate) * 10000 +MONTH(@fromdate) * 100 +DAY(@fromdate)  
select @to = YEAR(@todate) * 10000 +MONTH(@todate) * 100 +DAY(@todate)  

select accountid , las.acctnm ,sum(amt) as Amount from nbfcledger led left join tbl_LASClientmaster las on led.AccountID=las.LasAcctNo  
  where glcode='INTRND' and dr_cr='d' and     
valuedate >= @from and valuedate <= @to  
group by accountid,las.acctnm   
end
Run Code Online (Sandbox Code Playgroud)

Igo*_*nko 6

仅在 SQL Server 2014 中引入的本机编译存储过程才支持和需要架构绑定。

这就是您在 SQL Server 2008 中收到错误的原因。