Results 1 to 5 of 5

Thread: Help

  1. #1
    Join Date
    Mar 2012
    Posts
    2

    Unanswered: Help

    I'm trying to use a conditional statement in the where clause.

    Here is my table
    UID Amount ID PID Amount2
    1 30000 8064 NULL NULL
    2 30000 8042 8064 30000

    What I'm trying to achieve:
    • If Amount = Amount2 for UID 2 then show UID 1


    If anybody could steer me in the right direction, I would appreciate it. I'm not advanced in SQL, so please put some examples down. Thanks.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    The reason you are having trouble writing this statement is that it is not the type of statement that SQL is really supposed to handle. And the reason that it is not the type of statement that SQL is really supposed to handle is most likely due to your table structure not being designed properly.

    To do this with your current schema, you'll have to write a SELECT statement that join two instances of this table to itself, on sequential ID values. I could give you code for this, but even then I suspect it is not going to achieve the result that you want.

    How about you give us a few more details regarding the business problem you are trying to solve?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Mar 2012
    Posts
    2

    Hey Blindman

    Yes, I know the tables are not structure well. It's what I got and I didn't create it.

    What I'm trying to achieve is:
    The table represents payments that have been entered into our system. The top row represents a "Pledge" (like an IOU), and the bottom row represents the "Payment" to that "Pledge". The way the db is structures, it adds 2 entries (don't know why their did that way). So, if a person "Pledges" an amount, then pays off the entire amount, I just want to show the "Payment". If the person "Pledges" and pays off partial amount, I want to reduce the "Pledge" and show the payment as well. I have the logic for the reduction, just don't know how to display just the payment if the entire pledge was paid.

    Any help would be appreciated.

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    What's unclear is how you relate record 2 to record 1. They seem to have no common key.
    Please don't tell me you rely on their sequential values being consistent? Is that the entire table schema?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    that's because it the next one in the "order" silly
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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