Hey guys, ive have a problem with the following table:
CREATE TABLE [dbo].[CA](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Type] [char](1),
[Percent] [numeric](19, 5) NULL,
[Crop] [int] NULL,
[Currency] [int] NULL,
[Ammount] [decimal](19, 5)
[ProductionSite] [int] NOT NULL
)
This table describes how a ProductionSite pays its suppliers. It may be with Crops, a money ammount or a Percentage of some other ammount not listed here.
The 'type' column is a discriminator which indicates what is the paying type. The thing is, you may pay with the three options at the same time, with two or with one. So, for a given ProductionSite you may have up to three rows in the table (this desing cannot be changed)
I need to create a view (SP/Triggers not allowed) that will show only one row per ProductionSite.
I not sure if im missing something, but im having a lot of trouble with this one :(
Almost forgot, this has an extra problem. The column order of the view must be always the same. Im saying this, as query plans are not always deterministic (if im correct) so a triple self association may give different results (in column/row order, not data)). Just to be clear,
SELECT * FROM A LEFT JOIN A AS B LEFT JOIN A AS C
may return a subset of the following:
columns(a) + columns(b) + columns(c)
columns(b) + columns(a) + columns(c)
etc..
any advice/answer will be very appreciated :)