是否可以使用表作为存储过程的输入?
EXEC sp_Proc SELECT * FROM myTable
我创建了一个函数来返回由单个记录组成的表。
ALTER FUNCTION dbo.preEmail
(
@Num INT,
@WID INT
)
RETURNS
@Results TABLE
(
WID char(10),
Company nchar(50),
Tech nchar(25),
StartDate datetime,
Description varchar(max),
Address varchar(200),
Phone varchar(15),
Status varchar(35)
)
AS
BEGIN
INSERT INTO @Results
(WID, Company, Tech, StartDate, Description, Address, Phone, Status)
SELECT WID, company, tech, startDate, description, address, phone, status
FROM wo_tbl
WHERE Num = @Number AND wid = @WID
RETURN
END
GO
接下来,我有一个存储过程,可以向上述记录中安排的技术人员发送电子邮件。
EXEC sp_emailTech @WID, @Company, @Tech, @StartDate, @Description, @Address, @Phone, @Status.
但我宁愿做
EXEC sp_emailTech SELECT * FROM dbo.preEmail(1, 5746)