【发布时间】:2017-04-20 16:39:11
【问题描述】:
目前有很多业务规则在存储过程中被硬编码。想要探索设置规则表的选项,我们打算在其中键入所有业务规则并基于它执行存储过程。
虽然系统有点复杂,但这里提供了一个简单的版本。
Create table tblTest
(
TranID int primary key not null,
FName varchar(20) not null,
Age int not null,
Salary money not null,
MaritalStatus char(1) not null
)
Insert into tblTest values (1, 'Alex', 26, '25000.00','Y')
Insert into tblTest values (2, 'Brenda', 25, '14500.00','Y')
Insert into tblTest values (3, 'Peter', 69, '50000.00','N')
Insert into tblTest values (4, 'Paul', 64, '74500.00','Y')
现在为了保持示例简单,我们假设业务规则如下:
1. 年龄 >=25,
2. 年龄
3. 薪水 > 15K
Create table tblBusRule
(
RuleID int Primary key not null,
ColName varchar(20) not null,
Operator varchar(2) not null,
ColValue varchar(10) not null,
RuleOrder int not null
)
Insert into tblBusRule values (1, 'Age', '>=', '25', 1)
Insert into tblBusRule values (2, 'Age', '<', '65', 2)
Insert into tblBusRule values (3, 'Salary', '>', '15000.00', 3)
直接查询是这样的,它会单独输出记录 1 (Alex) 和 4 (Paul)。
Select * from tblTest
where
age >=25 and
age < 65 and
salary > '15000.00'
现在如何根据 tblBusRule 中提到的规则使这个动态化?
【问题讨论】:
标签: sql-server-2008-r2 sql-server-2016