-2

I have a problem, how to search alphanumeric with range (start & end) such as below :

table

if i use BETWEEN, the result will problem with the number that have letter at the end, in pic/table = Input 2.

So, how can i to get the Id 6 result when keyin HSF3145858B

pls advise

Thank You

jarlh
  • 42,561
  • 8
  • 45
  • 63
twister
  • 41
  • 8

1 Answers1

0

That is because between uses alphabetical ordering. You should probably add another check to confirm that the searched code is the same length as the start and/or end. This could be done by putting parenthesis around the first clause and adding AND (len('$serialno') = len (Start))

This would lead to the following which should work

$tsql = "SELECT Product FROM tbl_serial_range WHERE ('$serialno' BETWEEN Start AND End) AND (len('$serialno') = len (Start)) ";
pteronewone
  • 170
  • 4