如何访问存储过程中声明的表的表列的值?

时间:2015-05-30 05:35:20

标签: sql sql-server stored-procedures sql-server-2012

我的存储过程是:

alter PROCEDURE uspApprovalHistory
    -- Add the parameters for the stored procedure here
            @empID int = null
AS
BEGIN
    declare @SRFTable table
    (SRFID nvarchar(50))
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    -- Insert statements for procedure here
    insert into @SRFTable
    Select MasterCode from CallForwarding 
    Where EmployeeNo = @empID or ApproverNo = @empID;

    Select * From callforwarding Where @SRFID[i] = Mastercode

END
GO

我想从名为CALLFORWARDING的表中选择所有行,其中SRFID = MasterCode。但是有多个SRFID保存在名为SRFTABLE的表中。如何遍历SRFTABLE中的所有不同SRFID以从CALLFORWARDING TABLE中获取所有匹配的记录。

1 个答案:

答案 0 :(得分:1)

这样的东西会起作用吗?

Select * From callforwarding 
Where Mastercode in (select distinct(SRFID) from SRFTABLE order by SRFID)