我正在尝试结合程序和函数来了解更多关于它们的内容。调用函数内部函数
我有一个名为customer
的表格,列数很少(我将使用的列为sal
)。
我创建了一个函数来检查谁的工资都低于25000.如果上述情况呈现行,然后我从我的函数调用过程。
该过程更新sal
(sal = sal + 1000
)并返回rowcount。
create procedure Taxrefund2(@taxr int) as
begin
update customer
set Balance=Balance + @taxr
return @@rowcount
end
create function taxfunc()
as
begin
declare @salary table(sal decimal(10,2))
set @salary = (select sal from customer)
declare @x int=0
if @salary < 25000
exec @x = taxrefund2(1000)
return @x
print 'the no of customers who got tax redeemption is :' +cast(@x as varchar(10))
当我编译我的功能我得到的错误:
消息156,级别15,状态1,过程taxfunc,行中的关键字 '作为' 近2
不正确的语法。Msg 102,Level 15,State 1,Procedure taxfunc,Line 8
'1000'附近的语法不正确。消息178,级别15,状态1,过程taxfunc,第9行
带有返回值的RETURN语句不能在此上下文中使用。Msg 102,Level 15,State 1,Procedure taxfunc,Line 10
')'附近的语法不正确。
有人能解释我在代码或概念中做了什么错误吗?
不能调用SQL Server用户定义的函数内的存储过程。而且你不能在一个函数内改变数据库的状态,但是你在代码中试图做什么可以通过一个存储过程来实现:) –
为什么你有SQL Server和MySql的标签? –
[可以在用户定义的函数中调用存储过程吗?]可能的重复?(http://stackoverflow.com/questions/12843788/is-it-possible-to-call-a-stored-procedure-in - 一个用户定义的函数) –