修改从DB获取的查询(即,考虑子句)当选择DROPDOWN项时

时间:2016-11-17 03:56:03

标签: dropdown

查询:

"SELECT COUNT(ID)AS 'COUNT(ID) from tbl_Leads WHERE UserID={Current User}"

修改:

if (Query.IndexOf("WHERE") > 0) {                        
    if (Query.Contains("UserID = {CurrentUser}")) {
        Query = Query.Replace("UserID = {CurrentUser}", "UserID IN (" + UserIDs + ")");
        if (dropdownValue != 0) {
            Query += "";
            Query+= "AND FKiLeadClassID="+dropdownValue;
        }
    }
    if (Query.Contains("OrganizationID = {CurrentUser}")) {
        Query = Query.Replace("OrganizationID = {CurrentUser}", "OrganizationID=" + OrganizationID);
        if (dropdownValue != 0) {
            Query += "";
            Query += "AND FKiLeadClassID=";
            Query += dropdownValue;
        }
    }                       
}     
else if(Query.IndexOf("WHERE") == 0) {
    if (dropdownValue != 0) {
        Query += " Where";
        Query += " FKiLeadClassID=";
        Query += dropdownValue;
    }
}

需要:请考虑" GROUPBY"和" ORDERBY"条款也是如此。

我想:

"SELECT COUNT(ID)AS 'COUNT(ID) from tbl_Leads WHERE UserID IN (234) AND FKiLeadClassID=43"   

(如果没有groupby或orderby)

OR

我想:

"SELECT COUNT(ID)AS 'COUNT(ID) from tbl_Leads WHERE UserID IN (234) AND FKiLeadClassID=43"  GROUPBY(something) ORDERBY(something).

0 个答案:

没有答案