CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2005
    Location
    Rhode Island, USA
    Posts
    52

    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.

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    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.

  3. #3
    Join Date
    Nov 2005
    Location
    Rhode Island, USA
    Posts
    52

    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.

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Problem with calling LENGTH() using parameters

    Well I have never used DB2, so I can't comment much.

  5. #5
    Join Date
    Nov 2005
    Location
    Rhode Island, USA
    Posts
    52

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured