Problem with calling LENGTH() using parameters
I am working on a DB2 system and am trying to call LENGTH() using sqlbindparameter on the following SQL command.
Code:
"SELECT COUNT(*) FROM CLAIM_TICKET WHERE ( (LENGTH(BARCODE) = 26 OR LENGTH(BARCODE) = 28) AND LENGTH('?') = 14 ) AND PIN = ?")
but it always returns back 0 rows even when the string that I binding is 14 characters long. I have tried removing the single quotes but then I receive and error. The PIN parameter works fine (tested by hardcoding the string for Length. Should I be using a different function for passing hte string placed into LENGTH?
Thanks.
Re: Problem with calling LENGTH() using parameters
Although I haven't worked on DB2, but from what I know you cannot pass a field name as a parameter. You need to specify a fieldname in place of ? or maybe build a dynamic SQL.
Re: Problem with calling LENGTH() using parameters
I tried passing "LENGTH('data')" as the contents of a ? but that failed too. I also haven't found another method call to use to pass the contents of LENGTH.
Re: Problem with calling LENGTH() using parameters
Well I have never used DB2, so I can't comment much.
Re: Problem with calling LENGTH() using parameters
I ended up solving the problem. for some bizarre reason I needed to do:
Code:
LENGTH(CONCAT(?,''))
to get it to work. Really weird but it DOES work. I found a remark about CONCAT in the change files for SQLBINDPARAMETER so figured I would give it a try.