1

我创建了一个存储过程,其中列出了会员资格还剩 7 天的所有客户。

CREATE PROC spGetMemReminder
AS
    SELECT users.fullname,
           membership.expiryDate
    FROM   membership
           INNER JOIN users
             ON membership.uid = users.uid
    WHERE  CONVERT(VARCHAR(10), expiryDate, 105) =
           CONVERT(VARCHAR(10), ( getdate() + 7 ), 105) 

我想自动将此列表插入到另一个表中。我如何实现这一目标?任何建议表示赞赏。谢谢

4

3 回答 3

0

剪了这个:

SELECT * INTO #MyTempTable FROM OPENROWSET('SQLNCLI', 'Server=    (local)\SQL2008;Trusted_Connection=yes;',
 'EXEC getBusinessLineHistory')

由此:将存储过程的结果插入临时表

于 2013-05-21T12:16:19.627 回答
0
Insert into YOUR_TABLE exec("spGetMemReminder")
于 2013-05-21T12:21:58.027 回答
0

另一个建议是……不要编写存储过程来插入临时表,因为数据总是在变化。

只需编写一个视图......并让您的“报告”使用/使用该视图。

if exists (select * from sysobjects 
    where id = object_id('dbo.vwExpiringMemberships') and sysstat & 0xf = 2)
    drop VIEW dbo.vwExpiringMemberships

GO


/*
select * from dbo.vwExpiringMemberships
*/

CREATE VIEW dbo.vwExpiringMemberships AS  

    SELECT usr.fullname,
           mem.expiryDate
    FROM   dbo.Membership mem
           INNER JOIN dbo.Users usr
             ON mem.uid = usr.uid
    WHERE  CONVERT(VARCHAR(10), expiryDate, 105) =
           CONVERT(VARCHAR(10), ( getdate() + 7 ), 105) 


GO



GRANT  SELECT ,  UPDATE ,  INSERT ,  DELETE  ON  [dbo].[vwExpiringMemberships] TO public
GO
于 2013-05-21T13:47:06.977 回答