0

我正在创建一个 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)
);
4

3 回答 3

4
CREATE FUNCTION dbo.AccountsOfTheUser
(@UserId INT)
RETURNS TABLE 
AS
RETURN
(
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)
 );
于 2013-05-21T13:14:08.527 回答
1
CREATE FUNCTION dbo.AccountsOfTheUser
(@UserId INT)
RETURNS TABLE
BEGIN  
    RETURN (SELECT ...)
END  
于 2013-05-21T13:38:42.690 回答
0

我看到的唯一问题是第二个RETURNS应该是RETURN

CREATE FUNCTION dbo.AccountsOfTheUser
(@UserId INT)
RETURNS TABLE 
AS
RETURN
于 2013-05-21T13:16:53.830 回答