|
|
本帖最后由 purple 于 2012-12-31 13:44 编辑
函数格式:
getWhereSQL (itemNames, conditions, fieldNames)
函数说明:
tableName :一般传查询表单的字段用[]扩住
conditions :查询方式 “like”“=”
fieldNames : 对应数据库里要查询的字段名 item_xxx
示例:
实现getWhereSQL(itemNames,conditions,fieldNames)函数的应用
function getWhereSQL(itemNames,conditions,fieldNames){
var sqlWhere = "";
for (var i = 0; i < itemNames.length; i++) {
var itemValue = getItemValue(itemNames);
if (itemValue != null && itemValue.trim().length() > 0) {
if (conditions == "like") itemValue = "%" + itemValue + "%";
var item = fieldNames;
//for Oracle
if (conditions == "<=" || conditions == ">=") {
item = "to_char(" + item + ",'yyyy-MM-dd')";
}
sqlWhere += " and " + item + " " + conditions + " '" + itemValue + "'";
}
}
return sqlWhere;
}
调用
#include " autosqllib";
getWhereSQL ("itemNames", " conditions","fieldNames"); |
|