CREATE  PROCEDURE dbo.addSource (
  @SourceID uniqueidentifier = NULL OUTPUT,
  @Site uniqueidentifier,
  @FilePath nvarchar(512),
  @Status nvarchar(20) = N'PENDING',
  @Parser nvarchar(15) = NULL,
  @LineNumber int = 0,
  @Length bigint = 0,
  @LastWrite datetime,
  @ReProc bit = 0,
  @Comment nvarchar(256) = N'This file has not yet been processed.'
) AS
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRAN

IF EXISTS(SELECT * FROM [LogSource] WHERE [FilePath] = @FilePath
  AND [Site] = @Site)
  SELECT @SourceID = [ID] FROM [LogSource] WHERE [FilePath] = @FilePath
    AND [Site] = @Site
ELSE
  INSERT INTO [LogSource] ([ID], [Site], [FilePath], [Status], [Parser], 
    [LineNumber], [Length], [LastWrite], [ReProc], [Comment]) VALUES 
    (@SourceID, @Site, @FilePath, @Status, @Parser, @LineNumber,
    @Length, @LastWrite, @ReProc, @Comment)

IF (@@ERROR <> 0)
  BEGIN
    ROLLBACK TRAN
    SET @SourceID = NULL
  END
ELSE
  BEGIN
    COMMIT TRAN
  END
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
