patindex vs charindex

  • patindex vs charindex

    Hello i couldnt find information which is better in perfomance , only i saw the diference, one permits to use wildcard and the other not, thats all i found but i couldnt find informations about the perfomance, i need to use someone in a trigger, which is recommendably to use??

  • I would say that if the functionality is sufficient, then use the charindex.

    If you do:

    DECLARE @sum FLOAT, @S VARCHAR(255)

    SELECT @S = 'foobar', @sum = 0.0

    WHILE @sum < 1000000 BEGIN

    SELECT @sum = @sum + CHARINDEX('o', @S)

    END

    SELECT @sum

    and

    DECLARE @sum FLOAT, @S VARCHAR(255)

    SELECT @S = 'foobar', @sum = 0.0

    WHILE @sum < 1000000 BEGIN

    SELECT @sum = @sum + PATINDEX('%o%', @S)

    END

    SELECT @sum

    there is no real performance difference.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply