Judging whether the record in the database exists with SQL statement

xiaoxiao2021-03-19  219

Alter Procedure WG_NEWS_INSERTCATEGORY

@Name varchar (50), @ Description Varchar (250), @ imageurl varchar (250), @ categoryid int outprutasdeclare @Currid Int

- See eti the category alleady exists

Select @currid = categoryid from news_categories where name = @Name

- IF not, add it

IF @CurrID IS NULL BEGIN INSERT INTO News_Categories (Name, Description, ImageUrl) VALUES (@Name, @Description, @ImageUrl) SET @CategoryID = @@ IDENTITY IF @@ ERROR> 0 BEGIN RAISERROR ( 'Insert of Category failed', 16, 1) RETURN 99 EndElse Begin Set @categoryId = -1 End

转载请注明原文地址:https://www.9cbs.com/read-130070.html

New Post(0)