2017-05-10 166 views
-1

我有嚴重的不知道什麼是錯在這裏..SQL - 問題聲明

USE [PRR_NEW] 
DROP FUNCTION [dbo].[fA_20] 
GO 
CREATE FUNCTION [dbo].[fA_20] 
( 
    @Id bigint = 10 
) 
RETURNS TABLE 
AS 
RETURN 
(
declare @m table 
(
    VatIdGA nvarchar(16), 
    VatIdCAT nvarchar(16) 
); 
insert into @m (VatIdGA, VatIdCAT) values(9, 8) 
insert into @m (VatIdGA, VatIdCAT) values(11, 3) 
insert into @m (VatIdGA, VatIdCAT) values(10, 5) 
insert into @m (VatIdGA, VatIdCAT) values(5, 9) 

select vr.*, m.VatIdGA 
    from VatRate as vr 
    left outer join @m as m on m.VatIdCAT = vr.Id 

問題是聲明...任何意見或解決方案?謝謝!

+1

標記您正在使用的dbms。該代碼是特定於產品的。 – jarlh

回答

1

從語法上看,這看起來像SQL Server。
如果是這樣,這應該工作:

CREATE FUNCTION [dbo].[fA_20] 
( 
    @Id bigint = 10 
) 
RETURNS TABLE 
AS 

RETURN 
(
    with m as 
    (
     select VatIdGA, VatIdCAT 
     FROM (values(9, 8), (11, 3), (10, 5), (5, 9)) v(VatIdGA, VatIdCAT) 
    ) 
    select vr.*, m.VatIdGA 
    from VatRate as vr 
    left outer join m on m.VatIdCAT = vr.Id 
)