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.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Yes, parameters.

  • sqlenthu 89358 wrote:

    Yes, parameters.

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

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • 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) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • 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