简体   繁体   中英

How to create a stored procedure with schemabinding?

I am trying to create a stored procedure with schemabinding but I am unable to do so.

Error:

An invalid option was specified for the statement "CREATE/ALTER PROCEDURE"

Is it even possible to create stored procedures with schema binding?

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

Schemabinding is only supported by, and required for, natively compiled stored procedures which were introduced only in SQL Server 2014.

That is why you are getting the error in SQL Server 2008.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM