我正在创建一个 T-SQL 函数,但出现错误:
必须声明标量变量@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)
);