SQL create a procedure with update and insert a other table
September 22, 2008
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
Entry Filed under: Database. Tags: author-pinal, data-warehousing, dba, dba-tool, msbuild, sql-add-on, sql-authority, sql-backup-and-restore, sql-data-storage, sql-datetime, sql-documentation, sql-download, sql-query, sql-tips-and-tricks, sqlauthority-news, t-sql, xquery.
Trackback this post | Subscribe to the comments via RSS Feed