I’m designing an ASP.NET Web Forms application that will be used to query the database dynamically with customized values and filters.
For example:
-
Pull up 3 fields: SKU, Description, Price, Color.
-
The value of Description should be ProductName + comma + space +
Description. -
The value of Price should be Price + 10.00.
-
The value of Color should be Red if the SKU = 123.
I need to store these “rules” in my SQL database so I can query my database at a later time based on these rules.
Initially, I was thinking to store the rule as SQL text like “ProductName + ‘, ‘ + Description”, and then use this in my dynamic SQL.
But there’s a few things that need wouldn’t work if I were to do that:
- Differentiating between column names and static text. ( I guess the single quotes would take care of that)
- Different data types (when concatenating let’s say)
- Case statements
- There are where clauses too.
I need ideas how to go about this – my database structure and how to query from these rules.
I’m using ASP.NET Web Forms, SQL Server database.
Thanks for any help.
I ended up creating a table with Fields (FieldID, FieldName), and Values(Value, ValueType, Datatype, FieldID). So, if I needed Description to equal to ProductName + comma + space + Description, I would have a record in Fields table with FieldName=”Description” and a value record for ProductName, comma+space and Description. ProductName and Description would have a ValueType of “Field” and “, ” (comma space) would have “Static”.
I then constructed my sql query with parameters based on these attributes.