Database stored procedure Implementation and deletion change (SQL SERVER 2008)

Source: Internet
Author: User
Tags datetime getdate

New data table:

CREATE TABLE [dbo].[szsj_message_list](    [ID] [int] IDENTITY(1,1) not NULL,    [name] [nvarchar]( +)NULL,    [message] [nvarchar]( the) not NULL,    [create_by] [nvarchar]( +) not NULL,    [create_date] [datetime]  not NULL,    [update_by] [nvarchar]( +)NULL,    [update_date] [datetime] NULL)  on [PRIMARY]

Realize:

CREATE PROCEDURE [dbo].[Op_announce_info]  @I_flag nvarchar( +), @id nvarchar( +), @title nvarchar( -), @content nvarchar(2048), @files nvarchar( +), @create_by nvarchar( +), @create_date nvarchar( +)  as BEGIN   if @I_flag = 'Insert'   beginINSERT  intoSzsj_announce_info (title, content, files, create_by, create_date) VALUES           (@title, @content, @files, @create_by, GETDATE()); End    if @I_flag = 'Update'   begin     UpdateSzsj_announce_infoSetTitle= @title, Content= @content, Files= @files, Update_by= @create_by, Update_date= GETDATE()      whereId= @id; End    if @I_flag = 'Updatetimes'   begin     UpdateSzsj_announce_infoSetTimes= IsNull(Times,0)+ 1      whereId= @id; End    if @I_flag = 'del'   begin     DeleteSzsj_announce_infowhereId= @id; End    if @I_flag = 'Show'   begin     Select *  fromSzsj_announce_infowhereCreate_datebetween GETDATE()- the  and GETDATE(); End    if @I_flag = 'Select'  Declare @sql NVARCHAR(MAX); Set @sql = 'SELECT * from Szsj_announce_info where 1=1'  begin   if LEN(@id)> 0  begin    Set @sql = @sql + 'and id =" " + @id + " '" ; End      if LEN(@create_date)> 0  begin    Set @sql = @sql + 'and CONVERT (date,create_date,120) = convert (date," " + @create_date + " ", +)' ; End     if LEN(@title)> 0  begin    Set @sql = @sql + 'and title like"'%' + @title + '%" " ; End  EXECsp_executesql@sql; End END

Database stored procedure Implementation and deletion change (SQL SERVER 2008)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.