日期:2014-05-17 浏览次数:20561 次
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Alarm_Status_tbl_AddOrUpdateStatus]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].Alarm_Status_tbl_AddOrUpdateStatus
GO
------------------------------------
--用途:有数据就更新, 没有数据增加一条记录
--项目名称:
--说明:
--时间:2012/12/3 16:16:19
------------------------------------
CREATE PROCEDURE Alarm_Status_tbl_AddOrUpdateStatus
@AS_Type int,
@C_ID int,
@IsValid bit,
@IsUsed bit,
@UpdateTime datetime
AS
Begin
DECLARE @isok int
Begin Try
Begin Transaction
UPDATE [Alarm_Status_tbl] SET
[IsValid] = @IsValid,[IsUsed] = @IsUsed,[UpdateTime] = @UpdateTime
WHERE [AS_Type] = @AS_Type and [C_ID] = @C_ID
if @@rowcount=0
begin
INSERT INTO [Alarm_Status_tbl](
[AS_Type],[C_ID],[IsValid],[IsUsed],[UpdateTime]
)VALUES(
@AS_Type,@C_ID,@IsValid,@IsUsed,@UpdateTime
)
end
Commit Transaction
set @isok =1
End Try
Begin Catch
Rollback Transaction
set @isok = -1
print error_number()
print error_message()
print error_state()
print error_severity()
End Catch
return @isok
End
GO