存储过程 创建全局临时表

来源:互联网 发布:樱井知香迅雷种子磁力 编辑:程序博客网 时间:2024/04/29 23:44
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE CreateTempTableForPostIdWithIdentity 
-- Add the parameters for the stored procedure here
@StartWith int
AS






BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;





--Create Temp Table
IF Object_id('Tempdb..##PostIdWithIdentity') IS NOT NULL  
DROP TABLE ##PostIdWithIdentity  
 
CREATE TABLE ##PostIdWithIdentity 
(
ID   int IDENTITY (1,1)     not null,
PostId nvarchar(255),
Tags nvarchar(MAX),
primary key (ID)   
)
truncate table ##PostIdWithIdentity 
insert into ##PostIdWithIdentity(PostId,Tags) select Id,Tags from [InstagramData].[dbo].[Post] 
Select Top(10)* from ##PostIdWithIdentity 


    -- Insert statements for procedure here
--SELECT row_number() over (order by Id asc) as id,Id as PostId,Tags From  [InstagramData].[dbo].[Post] 
END
GO



0 0