create FUNCTION test(@ProductID int)
RETURNS table
AS
declare @t Table(PClassID int,PClassName nchar(50),PClassParentID int,PClassIdentify varchar(20))
insert into @t select * from tproductclass
return select * from @t
GO
=================================
消息 156,级别 15,状态 1,过程 test,第 4 行
关键字 'declare' 附近有语法错误。--------请高人指点改成这样:
create FUNCTION test(@ProductID int)
RETURNS table
AS
begin
declare @t Table(PClassID int,PClassName nchar(50),PClassParentID int,PClassIdentify varchar(20))
insert into @t select * from tproductclass
return select * from @t
end
GO
=============================
消息 102,级别 15,状态 31,过程 test,第 9 行
'BEGIN' 附近有语法错误。
RETURNS table
AS
declare @t Table(PClassID int,PClassName nchar(50),PClassParentID int,PClassIdentify varchar(20))
insert into @t select * from tproductclass
return select * from @t
GO
=================================
消息 156,级别 15,状态 1,过程 test,第 4 行
关键字 'declare' 附近有语法错误。--------请高人指点改成这样:
create FUNCTION test(@ProductID int)
RETURNS table
AS
begin
declare @t Table(PClassID int,PClassName nchar(50),PClassParentID int,PClassIdentify varchar(20))
insert into @t select * from tproductclass
return select * from @t
end
GO
=============================
消息 102,级别 15,状态 31,过程 test,第 9 行
'BEGIN' 附近有语法错误。
RETURNS @t table(.....) -- 这样
AS
begin
declare @t Table(PClassID int,PClassName nchar(50),PClassParentID int,PClassIdentify varchar(20))
insert into @t select * from tproductclass
return select * from @t
end
GO
RETURNS @t table(PClassID int,PClassName nchar(50),PClassParentID int,PClassIdentify varchar(20))
AS
begin
insert into @t select * from tproductclass
return
end
GO--错了,这样
CREATE FUNCTION Sales.fn_SalesByStore (@storeid int)
RETURNS TABLE
AS
RETURN
(
SELECT P.ProductID, P.Name, SUM(SD.LineTotal) AS 'YTD Total'
FROM Production.Product AS P
JOIN Sales.SalesOrderDetail AS SD ON SD.ProductID = P.ProductID
JOIN Sales.SalesOrderHeader AS SH ON SH.SalesOrderID = SD.SalesOrderID
WHERE SH.CustomerID = @storeid
GROUP BY P.ProductID, P.Name
);
GO
insert into @t select * from tproductclass order by ...
insert into @t select * from tproductclass order by ...
--------------这样的话..每次循环都要去排序了....
RETURNS @t table
(
PClassID int,
PClassName nchar(50),
PClassParentID int,
PClassIdentify varchar(20)
)
AS
begin
insert into @t select * from tproductclass
return select * from @t
end
GO