问题创建功能 [英] Problem creating function

查看:66
本文介绍了问题创建功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在 SQL Server 2005 中创建一个函数.这是我的代码:

Hi

I''m creating a function in SQL Server 2005. Here is my code:

create function hello
(
 declare @var bigint;
)
as
set @var = (select * from tbldealres)



但是出现以下错误:



But the following error come:

Msg 156, Level 15, State 1, Procedure hello, Line 5
Incorrect syntax near the keyword ''declare''.
Msg 102, Level 15, State 1, Procedure hello, Line 6
Incorrect syntax near '')''.





Please, help me on this.

推荐答案

由于您违反了SQL函数语法,因此出现错误,请参见函数语法 ^ ]了解更多信息.

您可以像下面这样进一步改善您的功能.

You''re getting error because you''re violating SQL function Syntax, See function syntax HERE[^] for more.

You can further improve your function like below.

CREATE FUNCTION dbo.hello()
returns bigint
AS
BEGIN
 declare @var bigint;
 set @var = (select COUNT(*) from TestXML)
 return (@var)
END;


避免使用分号(;)
Avoid the semicolon (;)
create function hello
returns bigint

as 
begin
declare @var bigint
set @var = select <coloumn name=""> from tbldealres ( where clause optional to return a single column) 
return @var 
end
</coloumn>


这篇关于问题创建功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆