我有疑问的是这样一个集合:重写多个几乎相同的查询与不同的where子句
variable a = select field1 from table where field2 = 1
variable b = select field1 from table where field2 = 2
variable c = select field1 from table where field2 = 3
variable d = select field1 from table where field2 = 4
后来,一些工作已经完成,并且这些变量都依赖于特定的值时,以这样的方式
if aieou1 <> 0 then
CallProc(something, something else, something else, a)
end if
if aeiou2 <> 0 then
CallProc(something, something else, something else, b)
end if
if aieou3 <> 0 then
CallProc(something, something else, something else, c)
end if
if aeiou4 <> 0 then
CallProc(something, something else, something else, d)
end if
这对我来说似乎很可怕。四个几乎相同的查询,在这两个部分,只有轻微的差异。有什么更好的方法来重写这个?请注意,如果它有所不同,前四个查询中的“表”只有大约12行(并且可能永远不会有更多)。
目前,我想我需要多个变量。我看到的唯一的“清理”至少是使用一个查询,并有案例陈述。但我希望我可以进一步清理它 – 2014-11-25 15:03:33