0% found this document useful (0 votes)
109 views2 pages

Email Address Insert/Update Procedure

The document discusses a stored procedure that inserts or updates an email address record depending on whether an ID is passed. It also notes that procedures should generally be kept simple and not include complex logic to determine the required action.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views2 pages

Email Address Insert/Update Procedure

The document discusses a stored procedure that inserts or updates an email address record depending on whether an ID is passed. It also notes that procedures should generally be kept simple and not include complex logic to determine the required action.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

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?

You might also like