Hat jemand vielleicht einen Beispiel ?
Hier ist ein Beispiel aus SQL:
@id int,
@description nvarchar(100),
@contentTypeId int,
@sortOrder int
AS
DECLARE @returnValue int
IF (@id IS NULL) -- Insert a new item
BEGIN
IF NOT EXISTS (SELECT Id FROM Category WHERE Description = @description AND ContentTypeId = @contentTypeId)
BEGIN
INSERT INTO Category(Description, ContentTypeId, SortOrder) VALUES(@description, @contentTypeId, @sortOrder)
SET @returnValue = SCOPE_IDENTITY()
END
ELSE
BEGIN
SET @returnValue = -1 -- record already exists
END
END
ELSE -- update an existing item
BEGIN
IF NOT EXISTS (SELECT Id FROM Category WHERE Description = @description AND ContentTypeId = @contentTypeId AND Id <> @id)
BEGIN
UPDATE
Category
Set
Description = @description,
ContentTypeId = @contentTypeId,
SortOrder = @sortOrder
WHERE
Id = @id
SET @returnValue = @id -- return the id of the existing / updated record
END
ELSE
BEGIN
SET @returnValue = -1 -- record already exists
END
END
RETURN @returnValue
Vielen Dank im voraus,