Вы находитесь на странице: 1из 2

CREATE PROCEDURE sprocEmailAddressInsertUpdateSingleItem @id int, @email nvarchar (100), @emailType int, @contactPersonId int

AS DECLARE @ReturnValue int IF (@id IS NULL) -- New Item BEGIN INSERT INTO EmailAddress ( Email, EmailType, ContactPersonId ) VALUES ( @email, @emailType, @contactPersonId ) SELECT @ReturnValue = SCOPE_IDENTITY() END ELSE BEGIN UPDATE EmailAddress SET Email = @email, EmailType = @emailType, ContactPersonId = @contactPersonId WHERE Id = @id SELECT @ReturnValue = @id END IF (@@ERROR != 0) BEGIN RETURN -1 END ELSE BEGIN RETURN @ReturnValue END

GO

[Example From Imar Spaanjaars: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=419 ]

But generally, I keep stored procedures as simple as possible. Shoving a load of logic in the things to determine the action that should be taken based on inputs is, to my mind, a "bad thing", and is more likely to lead to maintenance problems. Would she also say that you have too many methods in your code-behind/BLL? Perhaps she would recommend that you combine all those as well?

Вам также может понравиться