Here’s the scenario: I have a table for SunflowerSeeds in SQL Server 2008.
CREATE TABLE [dbo].[SunflowerSeeds](
[Color] [nvarchar](50) NULL,
[SeedType] [nvarchar](50) NULL,
[Price] float NULL
)
For simplicity, I haven’t inserted long list of data.
Data insertion into the table looks like this:
Insert into [dbo].[SunflowerSeeds] (Color, SeedType, Price)
SELECT 'Yellow', 'Dwarf', 20
UNION ALL
SELECT 'Brown', 'Garden', 30
UNION ALL
SELECT 'Red', 'Garden', 35
Now I have been provided various matrices that could raise the price of the seed.
- Polenless (YES/NO): If YES, raise the price by 10%
- Height (> 13″): If YES, raise the price by 8%
- Organic (YES/NO): If Yes, raise the price by 15%
- Lifecycle (Annual- YES/NO): If Yes, raise the price by 12%
Each data insert row could have YES or NO value to each of the matrix listed above. I need to come up with a process to return the new price based on the Price of each seed in the SunFlowerseeds table and taking into a/c the combination of matrices.
For e.g., if Yellow Dwarf is polenless, with height > 13”, Organic YES and having an annual life cycle then the new price has to be computed as
10% + 8%+15%+12% = 45% = 1+ 0.45= 1.45
Then new price is: 1.45 * Original Price= 1.45*20 = 29
Likewise for rest of the combination.
I’m thinking of writing a SQL Server stored procedure, so that it could be called in my C# code later. The i/p parameters for the stored procedure will be Color and SeedType. With those two parameters, I could get the Price.
The challenge is how do I compute the new Price for each of the seed with a combination of applicable matrices – Polenless, height, Organic, LifeCycle. Can anyone point me a proper way of doing it. Please kindly help me out. TIA.
Suppose that combination of Color and SeedType in SunflowerSeeds is unique:
Also you may use a bitwise flag of type int instead of @Polenless, @Height, @Organic, @Lifecycle.