Click to See Complete Forum and Search --> : Problem with calling LENGTH() using parameters


Ryland
August 17th, 2009, 03:47 PM
I am working on a DB2 system and am trying to call LENGTH() using sqlbindparameter on the following SQL command.


"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.

Shuja Ali
August 17th, 2009, 03:55 PM
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.

Ryland
August 18th, 2009, 07:40 AM
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.

Shuja Ali
August 18th, 2009, 01:40 PM
Well I have never used DB2, so I can't comment much.

Ryland
August 20th, 2009, 09:00 AM
I ended up solving the problem. for some bizarre reason I needed to do:


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.