I have the following table variable and the logic to populate this table is complex enough to where I need to include it in a separate stored procedure:
我有以下表变量,填充此表的逻辑足够复杂,我需要将它包含在一个单独的存储过程中:
DECLARE @UserExtendedSecurity TABLE
(
UserId UNIQUEIDENTIFIER,
UserName VARCHAR(500),
HasExtendedSecurity BIT
)
So let's say that I encapsulate this logic in another stored procedure named GetUserExtendedSecurityData
which returns a result with columns that map to the @UserExtendedSecurity
table variable above.
因此,假设我将此逻辑封装在另一个名为GetUserExtendedSecurityData的存储过程中,该存储过程返回一个结果,其中的列映射到上面的@UserExtendedSecurity表变量。
Let's say that my main stored procedure is named GetUsers
and that's where my primary @UserExtendedSecurity
table variable is defined.
假设我的主存储过程名为GetUsers,这是我的主要@UserExtendedSecurity表变量的定义。
How could I call GetUserExtendedSecurityData
from GetUsers
and populate the result into my primary @UserExtendedSecurity
table?
我如何从GetUsers调用GetUserExtendedSecurityData并将结果填充到我的主@UserExtendedSecurity表中?
2 个解决方案
#1
0
Seems like a normal INSERT INTO
:
看起来像普通的INSERT INTO:
CREATE PROCEDURE dbo.GetUsers
AS
BEGIN
/* some code */
DECLARE @UserExtendedSecurity TABLE
(
UserId UNIQUEIDENTIFIER,
UserName VARCHAR(500),
HasExtendedSecurity BIT
);
INSERT INTO @UserExtendedSecurity
EXEC GetUserExtendedSecurityData;
/* some more code */
END
#2
1
INSERT INTO @UserExtendedSecurityTable (UserName, HasExtendedSecurity)
EXEC GetUsers ...
GetUsers returns no results on its own, so the results from GetuserExtendedSercurityData get populated.
GetUsers自己不返回任何结果,因此GetuserExtendedSercurityData的结果将被填充。
#1
0
Seems like a normal INSERT INTO
:
看起来像普通的INSERT INTO:
CREATE PROCEDURE dbo.GetUsers
AS
BEGIN
/* some code */
DECLARE @UserExtendedSecurity TABLE
(
UserId UNIQUEIDENTIFIER,
UserName VARCHAR(500),
HasExtendedSecurity BIT
);
INSERT INTO @UserExtendedSecurity
EXEC GetUserExtendedSecurityData;
/* some more code */
END
#2
1
INSERT INTO @UserExtendedSecurityTable (UserName, HasExtendedSecurity)
EXEC GetUsers ...
GetUsers returns no results on its own, so the results from GetuserExtendedSercurityData get populated.
GetUsers自己不返回任何结果,因此GetuserExtendedSercurityData的结果将被填充。