當你不使用相關的過濾器時,你將參數設置爲NULL,對嗎?在這種情況下
WHERE isnull(@ts, [ts]) = [ts]
and isnull(@username, [username]) = [username]
and isnull(@ip, [ip]) = [ip]
and isnull(@my_category, [my_category]) = [my_category]
and isnull(@my_name, [my_name]) = [my_name]
and isnull(@nm1_name, [nm1_name]) = [nm1_name]
and isnull(@param, [param]) = [param]
and isnull(@short_descr, [short_descr]) = [short_descr]
option (recompile)
我提倡用選項(重新編譯)
編輯:
所以,你可以使用這樣的查詢
與 '',而不是NULL
WHERE @ts in ('', [ts])
and @username in ('', [username])
and @ip in ('', [ip])
and @my_category in ('', [my_category])
and @my_name in ('', [my_name])
and @nm1_name in ('', [nm1_name])
and @param in ('', [param])
and @short_descr in ('', [short_descr])
(不是使用或每一次更具可讀性和它不需要重新編譯*)
(*)作爲參數不會反正嗅
林不知道你想做什麼。你的意思是你想根據傳入的參數來做不同的過濾器嗎? –