SQL create a procedure with update and insert a other table

September 22, 2008 at 7:35 am Leave a comment

CREATE PROCEDURE dbo.sp_UpdateLibList
@TableId     as numeric(18,0),
@descr1     as nvarchar(2048),
@descr2    as nvarchar(2048) = ‘ ‘,
@reftableid     as numeric(18,0),
@seealso     as nvarchar(2048),
@newsee    as numeric(18,0),
@UserID     as numeric(18,0)
AS
BEGIN
DECLARE    @Event_ID as Numeric(18,0),
@Table_Code     as nvarchar(50)

SET NOCOUNT ON
select @Table_Code = ( select Top 1 Table_Code from LibTables where Field_Code = ( select fieldcode from liblist where tableid = @tableid) )
if @Table_Code is not null
begin
UPDATE LibList
SET     descr1         = @descr1 ,
descr2         = @descr2 ,
reftableid     = @reftableid,
seealso        = @seealso,
newsee        = @newsee
WHERE tableid        = @tableid

INSERT INTO LibEvent ( Event_Type, TableId, Table_Code)
VALUES ( ‘U’, @TableId, @Table_Code )
SELECT @Event_ID = @@IDENTITY

INSERT INTO UserEvents ( [User_ID], Event_ID )
VALUES ( @UserID, @Event_ID )
end
END

Advertisements

Entry filed under: Database. Tags: , , , , , , , , , , , , , , , , .

Function Crop image Function field value is egual in .net c#

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


September 2008
M T W T F S S
« Aug   Oct »
1234567
891011121314
15161718192021
22232425262728
2930  

%d bloggers like this: