I have the following sql tables
oitems table
    +---------+-----------+----------+
    | orderid | catalogid | numitems |
    +---------+-----------+----------+
    | O737    |       353 |        1 |
    | O738    |       364 |        4 |
    | O739    |       353 |        3 |
    | O740    |       364 |        6 |
    | O741    |       882 |        2 |
    | O742    |       224 |        5 |
    | O743    |       224 |        2 |
    +---------+-----------+----------+
Orders table
+-----------------+------------+------------+
|         orderid | ocardtype  |   odate    |
+-----------------+------------+------------+
|     O737        | Paypal     |            | 'OK
|     O738        | MasterCard | 01.02.2012 | 'OK
|     O739        | MasterCard | 02.02.2012 | 'OK
|     O740        | Visa       | 03.02.2012 | 'OK
|     O741        | Sofort     |            | 'OK
|     O742        |            |            | 'ignore because ocardtype is empty
|     O743        | MasterCard |            | 'ignore because Mastercard no odate
+-----------------+------------+------------+
the reusltant datatable called result 
 +-----------+----------+--------------+
| catalogid | numitems | ignoreditems |
+-----------+----------+--------------+
|       353 |        4 |            0 |
|       364 |       10 |            0 |
|       882 |        2 |            0 |
|       224 |        0 |            7 |
+-----------+----------+--------------+
idea is to sum the numitems column for products that have the same catalogid depinding on the data in the oitems table with the following conditions
- if ocardtypeis empty then ignore thenumitemsand consider it as0in the sum and sum the ignored items to theignoreditemscolumn
- if ocardtypefor some order isMasterCardorVisaand theodateis empty then ignore thenumitemsand consider it as0and sum the ignored items to theignoreditemscolumn
- if ocardtypeisPaypalorSofort, then just do thenumitemssum without checking the date because those types require noodate
basicly i want to save the result datatable to a temporary datatable and load it to a vb.net datatable
i am having a hard time figuring out how to do this in an sql query! i need this as sql command for vb.net , was able to do it programmatically using vb.net datatables using loops and alot of checking using linq is an option, but i just need to get this from the server
 
     
     
     
    