Results 1 to 4 of 4

Thread: Help for SQL beginner

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    SMM, Maribor
    Posts
    7

    Question

    Hi!

    This is my problem:

    In my VB app I'm using dbGrid, which uses data control (Dat)as datasource.
    Dat.recordsource = "SELECT ID_buy, ID_sell, ID_produce FROM tbl1 WHERE IDNum = " & IDNumber <-- given from user

    Now, this works fine, the problem is just, that values in this table are just numbers (sort of ID_numbers) of activities, that are stored in others tables, e.i.

    tbl2
    ID_buy Activity [text]


    tbl3
    ID_sell Activity [text]

    tbl4
    ID_produce Activity [text]

    Now, what I'm asking is How to create query, that will return activities (from each tbl2, tbl3, tbl4) instead of of ID numbers of that activities.

    Thanks for help!

  2. #2
    Junior Member
    Join Date
    Mar 2000
    Posts
    18
    If you have MS-ACCESS the easiest thing to do is just define your query there run it to see wether the results are fine and then look at the SQL code and paste it into VB.

    I am using this quite often if I have a complicated query.

    At least you will get an idea of how the query should look like.

    I think you will end up with several INNER JOINS in your sql.
    Trying to use VB 5

  3. #3
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83
    Using Access is a good idea. I also use it.

    Code:
    Select
     tbl2.Activity,
     tbl3.Activity
    From
     tbl1,
     tbl2,
     tbl3
    Where
     tbl1.IDNum = IDNumber <-- given from user 
    And
     tbl2.ID_buy = tbl1.ID_buy
    And
     tbl3.ID_sell = tbl1.ID_sell
    Will give you a start of thinking.
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    SMM, Maribor
    Posts
    7

    Smile

    Thanks guys, I've done it in Access and it works fine.

    If someone is browsing through this thread looking for solution of
    similar problem, I did something like:

    SELECT tbl2.Activity, tbl3.Activity,
    tbl4.Activity, tbl5.Activity
    FROM tbl5 RIGHT JOIN (tbl4
    RIGHT JOIN (tbl3 RIGHT JOIN
    (tbl2 RIGHT JOIN tbl1 ON
    tbl2.ID_buy= tbl1.ID_buy) ON
    tbl3.ID_sell=
    tbl1.ID_sell) ON
    tbl4.ID_produce=
    tbl1.ID_produce) ON
    tbl5.ID_other= tbl1.ID_other

    ** rules for spliting commands not used

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