在存储过程中更新查询 [英] update query in stored proc
问题描述
大家好,
我创建了存储过程
Hi every one,
I have stored procedure created
USE [WAAS]
GO
/****** Object: StoredProcedure [WAAS].[ADMIN_ADD_TEMPLATES] Script Date: 11/30/2012 12:00:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [ADD_RECORDS]
(
@GrpId bigint,
@DispName varchar(50),
@FullName varchar(50),
@LastValue varchar(50),
@ActiveDirName varchar(50),
@ClassVal int,
@UID varchar(15)
)
As
BEGIN
INSERT INTO table(GrpId,
DispName,
FullName,
LastValue,
ActiveDirName,
ClassVal,
CreatedBy,
CreatedDt)
VALUES(@LobGrpId,
@DispName,
@FullName,
@LastValue,
@ActiveDirName,
@ClassVal,
@UID,
GETDATE())
END
这是我创建的存储过程,用于将记录添加到数据库中。
现在我想通过编写更新查询来更新详细信息以更新同一存储过程中的值。
值需要更新:
This is my stored procedure created to add records into database.
Now I would like to update the details by writing the update query to update the values in the same stored procedure.
values needs to be updated:
LobGrpId
FullName
ActiveDirName
ClassificationVal
UID
updatedby
updatedtime
<无线电通信/>
任何人都可以帮助我吗?
提前致谢
Can anyone help me?
Thanks in advance
推荐答案
嗨..
在INSERT查询之前,您需要检查表中是否有相同的@LobGroupId记录。在您的存储过程中尝试以下过程..
Hi..
Before INSERT query you need to check whether there is a record with same @LobGroupId in your table. Try the following procedure in your Stored proc..
IF EXISTS(SELECT * FROM Table Where GrpId = @LobGroupId)
BEGIN
-- write your Update query
END
ELSE
BEGIN
-- write your Insert query
END
注意: - 在存储过程的参数部分中将参数@GrpId bigint重命名为@LobGrpId bigint ..
谢谢
Note :- Rename the parameter @GrpId bigint to @LobGrpId bigint in the parameter section of your Stored procedure..
Thank you
Hope
GrpId
在此表中是唯一的。如果是这样,检查是否存在并可以相应更新或插入
例如:
is unique in this table. if so, check for existence and can update or insert accordingly
Ex:
你可以做一件事你可以通过1如插入2作为更新3作为删除等等,如果你想插入2更新
并检入if(@ check = 1)然后在开始和结束块写入,则传递值为1插入查询
并检查是否(@ check = 2)然后在开始和结束块写更新查询等等...
You can do one thing u can pass 1 as insert 2 as update 3 as delete and so on pass the value with value 1 if u want to insert 2 to update
and check in if(@check=1) then in begin and end block write insert query
and check if (@check=2)then in begin and end block write update query and so on...
这篇关于在存储过程中更新查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!