Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Cant get right result from my query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

7 Posts

Posted - 04/09/2013 :  08:36:59  Show Profile  Reply with Quote

I have multiple tables:

       order (id,quantity, status, notes, item_id, customer_id)
       item (id,number, name)
       order_items(order_id, item_id)
       customer(id, name)

I have simple program in which in main window I have orders and their statuses(done, pending) that I show on `datagridview`. If I double click on a row, I collect new variable which is basically `order_id` and then I open my order with items ordered in new `datagridview`. But I just can't get right result in second datagridview.

With code bellow I fill my first datagridview

Dim sql As String = "SELECT DISTINCT, order.status, order.notes, order_items.oder_id FROM ((order INNER JOIN order_items ON = order.items_order_id) INNER JOIN customer ON order.customer_id ="

When I double click on a row I get variable `` as integer and then I use it in code bellow.

Dim sql As String = "SELECT item.number,, order.status, order_notes FROM  ((order INNER JOIN order_items ON = order_items.order_id) INNER JOIN  item ON order_items.item_id = WHERE (order_items.order_id = " & cellcliked.value & ")"

The items are showing fine (number, name) but the order(status, notes) is the same as first item on my order. For every item that follows on that order. Just cant' get it.

Flowing Fount of Yak Knowledge

4614 Posts

Posted - 04/09/2013 :  12:14:55  Show Profile  Reply with Quote
If I'm reading that correctly, then that is expected behavior. You have multiple Items per Order. the Order, presumably, only has one Status and Note. So you will get the same Status and Note for each item associated with that order. If that is an incorrect reading of what your posted above, please post sample data in a consumable format and expected outpout and we can help you better.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000