2013-11-20 149 views
0

我有一個多值參數@products,主數據集必須根據提供給@products的值獲取特定ID的數據。 我將@products的可用值作爲特定值(a,b和c)。主查詢是一樣的東西多值參數SSRS

select version,date from table 
where (@products=a and id in('1','2','3') 
or @products=b and id in ('4','5','6') 
or @products=c and id in('7','8','9')) 

當選擇@products只有1個值也能正常工作,但在選擇多個值拋出一個錯誤。

任何人都可以請幫我解決這個問題。

+0

未聲明@ products.The錯誤是數據集'Common'的查詢執行失敗',' – user2974732

+0

@avinash附近的語法不正確傳遞給數據集「Common」的參數的值爲as = Parameters!僅限於Product.Value。 – user2974732

回答

2

如果您將多個值傳遞給@products,那麼您不希望有一個where子句來檢查@products是否等於某個值,因爲那裏有多個值。也許可以重寫這樣的查詢:

select version, date from table 
where (('a' in (@products) and id in ('1','2','3')) 
    or ('b' in (@products) and id in ('4','5','6') 
    or ('c' in (@products) and id in ('7','8','9'))) 

我假設您傳遞給@products的值是字符串/文本。我不確定爲什麼你將ID作爲文本,因爲我猜它們是整數,但是因爲我沒有這些信息,所以我將它們留在查詢中,就像以前一樣。

+0

謝謝。有效.. – user2974732