I have a database that stores customer invoices information in the following fashion
< Invoice - Customer Customer ID Customer ID Store Invoice Item Details InvoiceItemITS - For customers, / P> InvocieItemTP - Store invoice item details for TP customers Details - Store General Invoice Item Details I have to show all invoice items for both customers (both types) for the given month. The result should include the details of all the columns of the customer and the invoice table and the common columns and invoitesitets in Invoice ITMP should be manually entered with the details columns if it is a general description for the other details details table. InvoiceITs and invoices ITMT are mutually exclusive and nearly half the columns are in common. I need help in invoicing and invoicing ITMTP to incorporate common columns into a set of columns and decide the details of each line. how can I do this? FYI: I can not add or change columns in tables or database structures You can use
ID Month Customer ID Total Amount
id InvoiceID DescriptionI D Price Volume Amount Details A ???? - Non-General details entered in the manual pipeline
ID InvoiceID DescriptionID Value Volume Amount Transaction Start Date End Date
ID name
LEFT JOIN both tables and then
CASE on
type to select from the appropriate table. Here's a sample for some columns, you can do it for all the columns.
SELECT c.ID, c.Name, c.Type, i.Month, i [Total amount], when the case is c.Type = 'its' then its.Price otherwise tp.Price end -construct the value for the common column, as the case c.Type when' its' then its.Volume when ' T.P. ' Then tp.Volume or Zero End Quantity - or something like this, is the case when c.Type = 'its' then details as COALESCE (its.Description, dits.Name) and dtp.Name end - Customer For the left description of this, join the invoice in the on.CustomerID = c.ID join the left InvoiceItemITS on its own.InvoiceID = in.ID on the left Join InvocieItemTP tp on tp.InvoiceID = in.ID Join Left [Details ] Include DTP .id = tp.DescriptionID left on DTP [details] DITIIT ID on Id = its Descript ID
No comments:
Post a Comment