0

我在 SQLServer 2005 中编写了以下函数

以下是函数:

create function fnBillParticulars()
return table
as
return (select * from billParticulars where Id='2425')
go

它给了我以下错误:

1.Msg 156, Level 15, State 1, Procedure fnBillParticulars, Line 2
  Incorrect syntax near the keyword 'return'.

2.Msg 178, Level 15, State 1, Procedure fnBillParticulars, Line 4
  A RETURN statement with a return value cannot be used in this context.

可能是什么错误?

请帮我。

4

3 回答 3

3

请试试:

create function fnBillParticulars()
returns table
as
return (select * from billParticulars where Id='2425')
go
于 2013-05-16T09:50:43.743 回答
1

您也可以在此创建一个VIEW

CREATE VIEW fnBillParticulars
AS
select * 
from billParticulars 
where where Id='2425'

或者如果你想table valued function

CREATE FUNCTION fnBillParticulars()
RETURNS @BillParticulars TABLE 
(
   Id       int,
   -- other columns here
) 
AS
BEGIN
   INSERT INTO @BillParticulars (Id, ...) -- specify columns here
    SELECT  * 
    FROM    billParticulars 
    WHERE   Id = '2425';

   RETURN;
END;
于 2013-05-16T09:50:48.653 回答
1

你在查询中写了两次“where”。

查询应该是:

select * from billParticulars where Id='2425'

并使用“退货”表

create function fnBillParticulars()
returns table
as
return (select * from billParticulars where Id='2425')
go
于 2013-05-16T09:55:01.073 回答