zoukankan      html  css  js  c++  java
  • 插入数据的存储过程的经典例子

    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
  • 相关阅读:
    GDB的Breakpoint, Watchpoint和Catchpoint
    sed初学
    比较两个文本不同的行/比较两个文本相同的行
    sprintf()函数基本用法
    vim不用鼠标复制粘贴
    SQL基础-语法
    SQL基础-简介
    XPath学习笔记
    jQuery选择器
    Ubuntu常用命令
  • 原文地址:https://www.cnblogs.com/sunxi/p/4497493.html
Copyright © 2011-2022 走看看