我創建一個T-SQL函數,我得到了一個錯誤:SQL函數 「聲明標量變量」
Must declare scalar variable @UserId
代碼:
CREATE FUNCTION dbo.AccountsOfTheUser
(@UserId INT)
RETURNS TABLE
AS
RETURNS
(
SELECT
dbo.accounts.account_id, dbo.accounts.account_name,
dbo.account_type.description, dbo.users.user_name, dbo.users.first_name,
dbo.users.midle_name, dbo.users.email, dbo.account_type.type_name
FROM
dbo.accounts
INNER JOIN
dbo.account_type ON dbo.account_type.type_id = dbo.accounts.type_id
INNER JOIN
dbo.users ON dbo.accounts.user_id = dbo.users.user_id
WHERE
(dbo.accounts.user_id = @UserId)
);
'AS RETURNS'應該是'AS RETURN'除了它看起來好像mssql –
@AlexK。做出答案? – gbn
雖然執行時得到的錯誤信息是'RETURNS''附近的錯誤語法。我認爲'必須聲明標量變量@UserId'顯示爲intellisense? –