## sql 问题关于公式计算的挑战

```declare
@M decimal(18,2)
set @M=18.5;
with Configer as(
select 'code1'as code,'M>21&M<65' as configer
union
select 'code2'as code,'M<=30' as configer
union
select 'code3'as code,'M*10<=200' as configer
union
select 'code4'as code,'M-10>15' as configer
union
select 'code5'as code,'(M-10)*5>10' as configer
union
select 'code6'as code,'M=18.5' as configer
)

select code,REPLACE(REPLACE(configer,'M',convert(varchar(20),@M)),'&',' and ') as Formula from Configer

除了循环之外 有没有其他方式可以直接获取出公式满足的结果集？

```

### 以下是问题补充：

@那天早上：没人回啊 算了 自己写了个喳喳 各位可以指点下 (2015/06/04 17:46)
@那天早上：declare @M decimal(18,2),@sql varchar(max) set @sql=''; set @M=18.5; with Configer as( select 'code1'as code,'M>21&M<65' as configer union select 'code2'as code,'M<=30' as configer union select 'code3'as code,'M*10<=200' as configer union select 'code4'as code,'M-10>15' as configer union select 'code5'as code,'(M-10)*5>10' as configer union select 'code6'as code,'M=18.5' as configer ) select @sql=REPLACE(REPLACE(( select ' select '''+code+''' where '+REPLACE(REPLACE(configer,'M',convert(varchar(20),@M)),'&',' and ') +' union' from Configer for xml path('')),'>','>'),'<','<') set @sql=left(@sql,len(@sql)-5) exec (@sql) (2015/06/04 17:46) 