【发布时间】:2020-09-28 07:56:04
【问题描述】:
我试图从数据库中获取一些数据。我需要从我的表中获取帐户信息 - 这种类型的信息将取决于用户。如果他/她将插入 account type = 1 -> 他将获得此信息。如果它取决于用户,我如何创建查询:例如,用户可以选择一种或多种帐户类型以及如何显示我的查询? 现在我有类似的东西:
SELECT accountID, accountName,AccountNo,accountType from account_ref
where accountType not in (4, 9) and accountType IN (1, 2, 3)
但帐户类型可以是 1,也可以不是。
编辑: 好吧,如果我尝试从我的程序中设置这个属性(它是 c#) 在这种情况下,我创建了方法:输入参数 - 它是带有 AccountType 的列表(哪个用户打开了) 如何动态设置它
public async Task<IList<AccountInfo>> GetAccountByAccountType(IList<AccountType> item)
{
//item
string query = $"SELECT accountID, accountName, AccountNo, accountType from account_ref " +
"where accountType not in (4, 9) and accountType IN(1, 2, 3)";
var accType = await Connection.QueryAsync<AccountInfo>(query);
return accType.ToList();
}
【问题讨论】:
-
你使用 MySQL 还是 SQLServer ?
-
accountType = 1 or 2 or 3- 这是错误的,必须是accountType IN (1, 2, 3)。这使得accountType not in (4, 9)多余。 -
我使用 SQLServer。
-
好吧,这个实现是正确的,但是这里设置了3个参数accountType IN (1, 2, 3)。我想动态设置它。有可能吗?
标签: c# sql .net sql-server ado