I have two tables:
CREATE TABLE [NEWS]
(
[ID] INT IDENTITY(1,1) NOT NULL,
[TITLE] VARCHAR(500) NULL,
[CONTENT] VARCHAR(800) NULL,
[CREATED] DATETIME DEFAULT(GETDATE())
PRIMARY KEY ([ID])
)
CREATE TABLE [LOG]
(
[ID] INT IDENTITY(1,1) NOT NULL,
[ACTION] VARCHAR(500) NULL,
[CREATED] DATETIME DEFAULT(GETDATE())
PRIMARY KEY ([ID])
)
I want to do the following procedure:
I have an input parameter @NewsId.
STEP 1
- If
NewsIdisNULL: I want to save the row into the table (NEWS) . - If
newsidis defined then I want to update the row.
STEP 2
- I want to do step 1 and then save the record into a table named
LOG. INSERT INTO LOG ("Action") VALUES ("insert or update")
How can I do these two steps using stored procedure?
How can I make one step after the successful completion and go to step 2?
Here is a simple sample to get you going.
from CodeProject: