데이터를 삽입하는 저장 과정의 대표적인 예

16423 단어 저장 프로세스
USE [Edushi_Fx]

GO

/****** Object: StoredProcedure [dbo].[Proc_LvYouGongLue_Inst] Script Date: 05/12/2015 14:50:58 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER PROC [dbo].[Proc_LvYouGongLue_Inst]



@Title    varchar(200),    --      

@CityCode     varchar(100),    --    

@Fee VARCHAR(10), --  

@Tag varchar(100),    --  

@Typeid     int,     --   0 1 2 3 4 

@Days    int,    --   0 1 2 3 4 

@Begtime datetime, --        

@LinkUrl varchar(200),--         

@Description    varchar(8000)    --    

AS

Begin



IF @Title<>'' And @Typeid<>'' AND @CityCode<>'' AND Len(@Description)>300

BEGIN

IF exists(select 0 from [SNS_UserBlog] where Title=@Title and CreatedDate>GETDATE()-3)



begin 

return 

end 



Declare @City int,--  ID

@nid int,--   ID

@name varchar(50),--  

@DayTypeid int--    

SELECT top 1 @nid=[UserID],@name=[NickName]FROM [Edushi_Fx].[dbo].[Accounts_Users] au WHERE au.UserID IN (1,27) order by newid()



Select Top 1 @City=RegionId FROM [dbo].Ms_Regions

Where RegionName=@CityCode

IF @City IS NULL

Begin

SELECT @City=0

End    

IF @Days<>''

BEGIN

SELECT @DayTypeid=CASE 

WHEN @Days BETWEEN 1 AND 3 THEN 1 

WHEN @Days BETWEEN 4 AND 7 THEN 2

WHEN @Days BETWEEN 8 AND 10 THEN 3

WHEN @Days BETWEEN 11 AND 15 THEN 4

WHEN @Days>=15 THEN 5 

END



insert into [SNS_UserBlog]([Title],[Summary],[Description],[UserID],[UserName],[LinkUrl],[Status],[Keywords],[Recomend],[Attachment],[Remark],[PvCount],[TotalComment],[TotalFav],[TotalShare],[Meta_Title],[Meta_Description],[Meta_Keywords],[SeoUrl],[StaticUrl],[CreatedDate],[CityID],[CategoryID],[PicURL],[Fee],[Tag],[Days],[StartDate],[EndDate])



values(@Title,null,@Description,@nid,@name,@LinkUrl,0,null,0,null,null,cast(ceiling(rand() * 100) as int) ,0,0,0,null,null,null,null,NULL,CONVERT(VARCHAR(100),GETDATE(),120),@City,0,NULL,@Fee,@Tag,@DayTypeid,@Begtime,CONVERT(VARCHAR(100),DATEADD(DAY,@Days,@Begtime),120)) 

end 

end

END

좋은 웹페이지 즐겨찾기