我有疑問的是這樣一個集合:重寫多個幾乎相同的查詢與不同的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