我正在寫一個查詢,確實對數據庫表各種檢查,並返回結果的摘要(在一個單一的結果集)UNION與IF語句
IF (select COUNT(*) from member_table WHERE password IS NULL) > 0
SELECT 'password check' as name, 'ERROR' as result ,'there is user(s) with blank password' as description
ELSE
SELECT 'password check' as name, 'COMPLETED' as result, 'OK' as description
UNION
IF (select COUNT(*) from server_context_properties) = 0
SELECT 'context properties check' as name, 'ERROR' as result ,'no context property has been entered' as description
ELSE
SELECT 'context properties check' as name, 'COMPLETED' as result, 'OK' as description
結果表應該是這樣的:
name result description
password check COMPLETED OK
contex properties check ERROR no context property has been entered
我知道語法是不正確的,但我想不出有什麼辦法來實現這一點。
我認爲這是最好的。似乎非常可擴展和乾淨:) – Joe 2011-03-17 18:47:56