• scziege (7/2/2009)


    In addition I add the execution plan as txt file. I think the most performance is consumed by the insert statement. But take a look and give me your feedback.

    You should disregard the estimated cost percentages when looking at plans - they are wildly inaccurate much of the time (for good reasons).

    For example, the call to your function ([Expr1000] = Scalar Operator([NestleDECodes].[dbo].[RNGCharacterMask]((8),N'34679CDFGHJKLNPRTVXY'))) is costed at 0.0000001 units (0%) since the server has no way to know how expensive the function call is in reality.

    Anyhow, as I hope you will now be able to test for yourself, the function call is probably over 99% of the cost of a real execution run.

    A few small points:

    IF NOT EXISTS (SELECT * FROM dbo.Codes WHERE code = @tempcode)

    ...is frequently more efficient than...

    IF (SELECT count(code) FROM codes WHERE code = @tempcode) = 0

    You should be careful to match data types. That lookup on code = @tempcode is less efficient than it could be due to an implicit conversion:

    CONVERT_IMPLICIT(nchar(10),[NestleDECodes].[dbo].[Codes].[Code],0)=[@tempcode]

    (The Code column is defined as CHAR(10) not NCHAR(10))

    The SET NOCOUNT OFF at the end of the procedure is pointless. SET NOCOUNT reverts to the setting in the outer scope when the procedure returns anyway.

    Paul