String Parse

  • David's solution looks faster to me, although it is probably not the most readable...

    You could also use (inspired by David's suggestion):

    select substring(string, PATINDEX('% [.0-9]%PT%', string) + 1,

    PATINDEX('%[0-9]PT%', string) - PATINDEX('% [.0-9]%PT%', string))

  • Yep but 'I did it my way' to avoid the third PATINDEX

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Are you worried about readability or performance? I hope SQL Server will realise that two of the patindexes are the same and not calculate it more than once...

  • quoteAre you worried about readability or performance?

    Both It depends on how many rows and how often the query is to be used, it's probably marginal either way.

    Admittedly I would normally layout the query differently for readability But felt lazy

    I will bow to your better judgement

    quoteI hope SQL Server will realise that two of the patindexes are the same

    You know what they say about assumptions....

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Don't say that my judgement is better - that's nonsense

    Which query is the most readable is probably subjective... Which one is fastest can however be determined by testing. I agree that it's probably marginal and also probably not important in this case. If it is, I guess Ryan will carry out the test and inform us about the result...

Viewing 5 posts - 16 through 19 (of 19 total)

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