Results 1 to 12 of 12

Thread: SQL 'n' CPP

  1. #1
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    SQL 'n' CPP

    Want to include a (currently) small SQL file with a CPP program. The line:

    WHERE type LIKE : parameter AND [number] > 0

    The 'parameter' (the space is there because I get a smiley otherwise) is supplied by text in a text field but I want to concatanate the any or no character '%' to either side of the parameter. Unfortunately i've completely lost it and no combination of ', ", or , produces anything other than an error.

    What is the syntax?

    Cheers
    To err is human. To really foul things up ... you need a computer.

  2. #2
    ?!
    Join Date
    Sep 2004
    Posts
    1,045
    Thanks
    2
    Thanked
    6 times in 5 posts
    Use the 'IN' clause, where you will be returning more than one result. IN matches the data against the parameter or subqueries etc.

    e.g,

    Select (columns)
    from (whatever your using)
    where (columns) in (parameter or subquery here) and
    (tuple) > 0

  3. #3
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    That dosn't appear to work in my case, do you know how I should concatenate the '%' in the SQL, I did it just the other day and now it's escaped me completely.
    To err is human. To really foul things up ... you need a computer.

  4. #4
    ?!
    Join Date
    Sep 2004
    Posts
    1,045
    Thanks
    2
    Thanked
    6 times in 5 posts
    You might find this useful : http://www.psoug.org/reference/conditions.html

  5. #5
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    I've tried the multiple wildcard method shown on that page many times:

    I know SQL syntax.

    Find any string that contains, anywhere, the letter 'S'
    SELECT ename FROM emp WHERE ename LIKE '%S%';

    but

    '%S%'

    dosn't work in a ParamByName query in CPP. The thing is I DID this just the other day, and it was simple, it can be easily done, I just cant remember or find an example anywhere.

    For example if I replace the parameter with an actual value like:

    '%value%'

    works perfect.
    Last edited by yamangman; 17-03-2005 at 10:09 PM.
    To err is human. To really foul things up ... you need a computer.

  6. #6
    ?!
    Join Date
    Sep 2004
    Posts
    1,045
    Thanks
    2
    Thanked
    6 times in 5 posts
    I didnt quite get what you wanted in the first place, hence why I threw the wildcard reference at you.

  7. #7
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    Thanks for your help anyway.

    Basically,

    '%value%' works, whereas

    '%parameter%' does not.

    Any ideas anyone?
    To err is human. To really foul things up ... you need a computer.

  8. #8
    Senior Member GAteKeeper's Avatar
    Join Date
    Feb 2004
    Location
    Derbyshire, UK
    Posts
    582
    Thanks
    14
    Thanked
    28 times in 22 posts
    • GAteKeeper's system
      • Motherboard:
      • MSI P67-GD5
      • CPU:
      • Intel i7 2600k
      • Memory:
      • 8Gb Corsair DDR3 1600
      • Storage:
      • ~44TB
      • Graphics card(s):
      • 980Ti
      • PSU:
      • Seasonic S12 600W
      • Case:
      • Lian Li PC-65
      • Operating System:
      • Win10 64bit
      • Monitor(s):
      • Dell U3415W & 2405fpw
      • Internet:
      • 45Mb vDSL
    are you building the SQL on the fly or using bind variables?
    Looking at your code I would guess at bind variables (the : kinda gives it away)
    this so Y not turn it into a string and concat the % in before binding.

    GAteKeeper
    Keeper of the Gates of Hell

  9. #9
    Pixel Abuser Spunkey's Avatar
    Join Date
    Nov 2003
    Location
    Milton Keynes
    Posts
    1,523
    Thanks
    0
    Thanked
    0 times in 0 posts
    i think + is the concatenator in SQL try '%' + parameter + '%'

  10. #10
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    I know that's it, i'm gonna go and try it now, thanks rubbishrubbishrubbishrubbishrubbishey.

    Thanks for the suggestion gatekeeper, but that's the first thing I did after the first 200 combinations of ", ', & and ,.
    To err is human. To really foul things up ... you need a computer.

  11. #11
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    WhoHoo! Thanks rubbishrubbishrubbishrubbishrubbishey You've helped me get back to exactly where I was 3 weeks ago
    To err is human. To really foul things up ... you need a computer.

  12. #12
    Pixel Abuser Spunkey's Avatar
    Join Date
    Nov 2003
    Location
    Milton Keynes
    Posts
    1,523
    Thanks
    0
    Thanked
    0 times in 0 posts
    no problemo, glad to help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 11
    Last Post: 08-03-2005, 10:15 PM
  2. SQL looking in another file?
    By Anders in forum Software
    Replies: 10
    Last Post: 01-02-2005, 08:16 PM
  3. My SQL, circular, inefficient ... or neither?
    By Anders in forum Software
    Replies: 14
    Last Post: 17-11-2004, 10:27 PM
  4. Oracle SQL
    By Raz316 in forum Software
    Replies: 7
    Last Post: 08-06-2004, 02:20 PM
  5. SQL help
    By Agent in forum Software
    Replies: 23
    Last Post: 11-11-2003, 09:22 AM

Posting Permissions

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