Skip to main content
Inspiring
May 10, 2023
Resuelto

Search result that has a C and a number after the C in the Part Number Field

  • May 10, 2023
  • 1 respuesta
  • 653 visualizaciones

I have a search results page that lists part numbers that engineers have to work on, but I only want part numbers displayed on the results page that have a C and then a number after the C in the part number. How do I write this in the Where statement in my CFQuery? If I write Where Part_Number Like 'C%', it lists all the parts that have anything after a C in the part number like CBT-BGA. I want it to find only part numbers like this: C4560. I also tried this: Where Part_Number Like '^C[0-9]', but this doesn't show any results. Thanks for your help.

    Este tema ha sido cerrado para respuestas.
    Mejor respuesta de jamie61880

    As it works without the "R", you are maybe on SQL Server. Try the following:

    WHERE code LIKE 'b[0-9][0-9][0-9][0-9]|c[1-3][0-9][0-6][4-8][0-9][1-7]' 
    -- matches B6942 and C280564

     


    This actually works the best because I don't have to specify a certain number of digits after the C:

    And Part_Number Like '[C][0-9]%'

    1 respuesta

    BKBK
    Community Expert
    Community Expert
    May 10, 2023

    What database brand are you using? I ask because pattern-matching depends on the database brand.

     

    For example, in MySQL, you can use the operator RLIKE for regular-expression pattern-matching:

    SELECT *
    FROM codeTBL
    WHERE code RLIKE 'b[0-9][0-9][0-9][0-9]' -- matches B6942
    Inspiring
    May 10, 2023

    Thank you! This worked, but I had to remove the "R" before the Like in your code above. Some part numbers have 4 digits and some have 5 or maybe even more than that. Do I have to do an Or statement for all these different variations with how many digits might be in the part number? I did this and it works, but what if we have a part number that has 10 digits in it and I don't have that in the where statement? It won't display that then. Also, I'm not sure what database brand I have. How do I tell if I'm using SQL or MySQL?

    jamie61880AutorRespuesta
    Inspiring
    May 11, 2023

    As it works without the "R", you are maybe on SQL Server. Try the following:

    WHERE code LIKE 'b[0-9][0-9][0-9][0-9]|c[1-3][0-9][0-6][4-8][0-9][1-7]' 
    -- matches B6942 and C280564

     


    This actually works the best because I don't have to specify a certain number of digits after the C:

    And Part_Number Like '[C][0-9]%'