嘿所有我想创建一个友好的UI来创建一个MS SQL查询字符串。到目前为止,我有以下代码用于保管箱框的 SELECT 部分:
//Logic for SELECT
$.each(_tmpSELECT, function (index, item) {
if (item == "AS") {
catchAS = true;
} else if (catchAS) {
//Get AS "zzzzz"
catchAS = false;
_SelectQuery = _SelectQuery.replace(/(^\s*,)|(,\s*$)/g, '');
_SelectQuery += " AS " + item + ", ";
} else if (item == "SUM") {
catchSUM = true;
} else if (catchSUM) {
//Get SUM("zzzzz")
catchSUM = false;
_SelectQuery += "SUM(" + item + "), ";
} else if (item == "DISTINCT") {
catchDISTINCT = true;
} else if (catchDISTINCT) {
//Get DISTINCT "zzzzz"
catchDISTINCT = false;
_SelectQuery += "DISTINCT " + item + ", ";
} else if (item == "TOP") {
catchTOP = true;
} else if (catchTOP) {
//Get TOP NNNN
catchTOP = false;
_SelectQuery += "TOP " + item + ", ";
} else {
_SelectQuery += item + ", ";
}
});
//Clean up...
SelectQuery = _SelectQuery.replace(/(^\s*,)|(,\s*$)/g, '');
哪种方法效果很好......但问题是,这只是查询的 SELECT 部分,我仍然有 WHERE & AND 部分要复杂得多,因为它有更多运算符要检查。
我想知道是否有人之前已经做过这样的事情并且愿意分享他们的代码...... 或知道通过 REGEX >执行此操作的更简单方法或类似的东西(LINQ等等)使用 javascript 或 jQuery ?
谢谢!