【发布时间】:2015-11-24 14:35:55
【问题描述】:
我需要创建一个可以根据选择的选项进行调整的 SQL 语句。我有 2 个从数据库中填充的下拉列表。
这是我的 ASP
<td class="theSearchTableData">
<asp:UpdatePanel runat="server" ID="up_team" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList runat="server" ID="ddl_team"></asp:DropDownList><%--AutoPostBack="true" OnSelectedIndexChanged="ddl_team_SelectedIndexChanged"--%>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td class="theSearchTableData">
<asp:DropDownList runat="server" ID="ddl_owner"></asp:DropDownList>
</td>
<td class="theSearchTableData">
<asp:DropDownList runat="server" ID="ddl_actionowner" ></asp:DropDownList>
</td>
c#代码
string Owner_ActionOwner_Combo = "";
string ownerClause = "";
string ActionownerClause = "";
if (ddl_owner.SelectedIndex > 0)
{
ownerClause = " log_number in (SELECT DISTINCT log_number FROM Log_Data WHERE log_owner = @logOwner) AND ";
}
if (ddl_actionowner.SelectedIndex > 0)
{
ActionownerClause = " log_number in (SELECT DISTINCT log_number FROM Log_Data WHERE log_owner <> @actionOwner and current_action_owner = @actionOwner ) AND ";
}
else if (ddl_actionowner.SelectedIndex >0 & ddl_owner.SelectedIndex > 0 )
{
Owner_ActionOwner_Combo = "log_number in (SELECT DISTINCT log_number FROM Log_Data WHERE current_action_owner = @actionOwner and log_owner =@logOwner) AND";
}
string completeWhereClause = ActionownerClause + Owner_ActionOwner_Combo + ownerClause;
“@”值已被参数化。
log_owner 通常是 action_owner,但是有一段时间 log_owner 与 action_owner 不同。这就是为什么我需要调整搜索条件。 如果用户想知道他们按日志所有者搜索的日志所有者,并且与操作所有者相同。问题是当他们同时搜索时。
我已将其输入我的数据库并获得了正确的数字。 log_owner 有 32 个,如果只有 action_owner 有 3 个,组合应该有 24 个。
感谢您的宝贵时间
【问题讨论】:
-
这在
ActionownerClauselog_owner <> @actionOwner中似乎没有必要 -
你能详细说明你的问题吗?
-
@JamieD77 我正在获取具有操作所有者但没有日志所有者的日志。这两个可以相同,但也可以在短时间内分配给其他人
-
@user449689 我添加了更多细节,
-
但是如果日志所有者实际上并没有从列表中选择一个并且只选择了一个操作所有者,那么您为什么还要关心谁呢?