birt用script實現模糊查詢(條件不帶%百分號)
//sql server
var stationName = params["stationName"]; var year = params["year"];
//此處的queryText默認是DataSet中的Query中的String,當Property Binding中有String時優先使用. //queryText = "select * from pems.dbo.warning";
if(stationName != "") {
queryText += " where stationName = '" + stationName + "'";
if(year != null && year != "") { queryText += " and startTime like '%" + year + "%'"; } } else { if(year != null && year != "") { queryText += " where startTime like '%" + year + "%'"; } }
//mysql var stationName = params["stationName"]; var year = params["year"];
//queryText = "select * from warning";
if(stationName != "") {
queryText += " where stationName = '" + stationName + "'";
if(year != null && year != "") { queryText += " and startTime like '" + year + "%'"; } } else { if(year != null && year != "") { queryText += " where startTime like '" + year + "%'"; } }
注意:
其中的null,其實不對應於參數裏的Null Value的,這個問題我沒找到,到底Null Value在script中接收到後是一個什麼值還不知道.null這個值是我自己隨意加的.if語句可以根據你的需要決定.