I have a look up table, basically with credit card types
ID | CCType |
-----------------------
1 | AMEX |
2 | VISA |
3 | MASTER CARD |
4 | OTHER |
Then I have another table with transactions where CCTypeID is the ID in the look up table
TransID | CCTypeID | TransactionName | OrderID |
-----------------------------------------------------
1 | 2 | BILLPAY |10
2 | 4 | SECUREPAYMENT |13
3 | 1 | BILLPAY |15
Then finally I have another table with the orders
OrderId | OrderDate | Product | TransID |
------------------------------------------------
10 | 2012-02-27 |Grapes | 1
13 | 2012-02-26 |Wine | 2
14 | 2012-01-26 |Pepper | 6
15 | 2012-01-26 |Apple | 1
I want to create a view that looks like this
OrderDate | CCType | Processed
----------- ---------------------------
2012-02-27 | AMEX | 0
2012-02-27 | VISA | 1
2012-02-27 | MASTER CARD | 0
2012-02-27 | OTHER | 0
2012-02-26 | AMEX | 0
2012-02-26 | VISA | 0
2012-02-26 | MASTER CARD | 0
2012-02-26 | OTHER | 1
I have tried to RIGHT OUTER JOIN the credit card types with the transactions on the CCTypeID and ID respectively, then a INNER JOIN with orders on ORDERID, grouped by ORDER.DATE and CardType but it only shows whereever there are values, is there a way to make it so that it still lists the credit card types no matter if there are transactions or orders for the date? just show zero for that card type?.
Will truly appreciate the help.
Your basic query should be something like this…
If you need “All Dates” to have values, then you need an extra table to join on. For example, make a table called
calendarand pre-populate it with all the dates you’ll ever need, then create an index on the date field. Then you can re-order your query to force every combination that you want a record for…