Query help

  • Hello friends,

    I have a requirement where I have to compare the two fields using regular expressions.

    Example, I have a parameter with value 'ABCDEF.%30a.3%a' or 'BBBB.%10a.5%a' where %30a or %10a tells the length of the name of the file, first set before '.' says the prefix and last one says the extension like '.abc' or '.pdf' or '.ghijk'. how can I compare with another Param where I send the name ?

    Are there any specific functions which help reduce the comparison ?

     

  • sqlenthu 89358 wrote:

    Hello friends,

    I have a requirement where I have to compare the two fields using regular expressions.

    Example, I have a parameter with value 'ABCDEF.%30a.3%a' or 'BBBB.%10a.5%a' where %30a or %10a tells the length of the name of the file, first set before '.' says the prefix and last one says the extension like '.abc' or '.pdf' or '.ghijk'. how can I compare with another Param where I send the name ?

    Are there any specific functions which help reduce the comparison ?

    A multi-value column is always going to lead to performance issues especially when you're trying to do comparisons.  I''d likely add 3 computed columns with each part split out into a separate column.  You can easily do that here with PARSENAME.

    https://docs.microsoft.com/en-us/sql/t-sql/functions/parsename-transact-sql

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Just to be clear, you are comparing the values of two parameters, is that right? Because you also mention 'fields', and it's not clear whether you mean values in a database, parameter values or something else.

    Can you provide a specific example? It would help us understand better.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Yes, parameters.

  • sqlenthu 89358 wrote:

    Yes, parameters.

    OK, please provide a couple of examples, along with the desired result.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • I don't think there any built-in functions that would directly help with that.

    As Phil suggested, post examples and he can help you with custom code to do it.

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • sqlenthu 89358 wrote:

    Yes, parameters.

    PARSENAME will still help in this case.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

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