I have adopted previously written BTQ's from a 3rd party.
We receive a flat file (I believe) from one of our clients each month. The record size varies.
For example. Say there are a total of 11 colums in the flat file as follows.
- CustID
- Prod1
- Value1
- Prod2
- Value2
- :
- Prod5
- Value5
Our client transmits the following (logical view).
CustID Prod1 Value1 Prod2 Value2 Prod3 Value3 Prod4 Value4 Prod5 Value5
C123 0010 10 0035 5 0085 99 0245 3 0900 14
C456 0035 75 0085 42 0900 6
This is what we receive (physical view).
C123,0010,10,0035,5,0085,99,0245,3,0900,14
C456,0035,75,0085,42,0900,6
As you can see, the record size varies because the client does not (will not) use NULL values in their records. *Don't know the reason, but I suspect that because we are dealing hundreds of thousands of records (I only listed 2 customers with 5 products) this reduces their transmit time and costs.
The 3rd party who developed the BTQ uses the following code to populate the table.
Insert Into tCustProd
CustomerID,
(case when Prod1N = 0020 then Value1V
else '' end ) as DressShoes,
(case when Prod1N = 0030 then Value1V
when Prod2N = 0030 then Value2V
else '' end ) as BollaHats ,
(case when Prod1N = 0040 then Value1V
when Prod2N = 0040 then Value2V
when Prod3N = 0040 then Value3V
Else '' end ) as SportsSocks ,
Not only are there hundreds of thousands of records, but there thousands of products. When the client adds a new product they do not use sequential Prod Numbers. For example, if they were to add were to 0010 0035, the above code would be changed to this (Changes are bolded).
Insert Into tCustProd
CustomerID,
(case when Prod1N = 0010 then Value1V
else '' end ) as TankTops,
(case when Prod1N = 0020 then Value1V
when Prod2N = 0020 then Value2V
else '' end ) as DressShoes,
(case when Prod1N = 0030 then Value1V
when Prod2N = 0030 then Value2V
when Prod3N = 0030 then Value3V
Else '' end ) as BollaHats,
(case when Prod1N = 0035 then Value1V
when Prod2N = 0035 then Value2V
when Prod3N = 0035 then Value3V
when Prod4N = 0035 then Value4V
Else '' end ) as CommandoBoots ,
(case when Prod1N = 0040 then Value1V
when Prod2N = 0040 then Value2V
when Prod3N = 0040 then Value3V
when Prod4N = 0040 then Value4V
when Prod5N = 0040 then Value5V
Else '' end ) as SportsSocks ,
Let me know if your require a deeper explanation.
Thank and God Bless,
Genesius