如何创建 SQL 运算符组合,如 ALL IN、NOT ALL IN
我的 Filter 类中有以下 4 个属性。我将把以下 4 个属性解析为 StoredProcedure 并获取过滤结果。
/// <summary>
/// Gets and sets comma seperated condition ids.
/// Patients must have all these conditions in order to satisfy the filter.
/// </summary>
public string MustHaveAllConditions { get; set; }
/// <summary>
/// Gets and sets comma separated condition ids.
/// Patients must not have all of these conditions in order to satisfy the filter.
/// </summary>
public string MustNotHaveAllConditions { get; set; }
/// <summary>
/// Gets and sets comma separated condition ids.
/// Patients must have at least one of these conditions in order to satisfy the filter.
/// </summary>
public string MustHaveAtLeastOneCondition { get; set; }
/// <summary>
/// Gets and sets comma separated condition ids.
/// Patients must not have at least one of these conditions in order to satisfy the filter.
/// </summary>
public string MustNotHaveAtLeastOneCondition { get; set; }
我的存储过程将有四个参数,如下所示。 例如:
@*MustHaveAll*条件 = "1,2"
@*MustNotHaveAll*条件 = "3,4"
@*MustHaveAtLeastOne*条件= "5,6,7,8"
@*MustNotHaveAtLeastOne*Condition = "9, 10"
我正在使用 UDF返回一个包含 Ids 列的表。
我的问题:
基本上我可以使用 SQL“IN”运算符来查找至少具有一种条件(即: @MustHaveAtLeastOneCondition )和“NOT IN”运算符组合来过滤 @MustNotHaveAnyConditions 的患者。
是否有任何 SQL 运算符(或简单的方法)来过滤 MustHaveAllConditions、MustNotHaveAllConditions 参数?
I have below 4 properties in a Filter class. I am going to parse below 4 properties to a StoredProcedure and get the filtered result.
/// <summary>
/// Gets and sets comma seperated condition ids.
/// Patients must have all these conditions in order to satisfy the filter.
/// </summary>
public string MustHaveAllConditions { get; set; }
/// <summary>
/// Gets and sets comma separated condition ids.
/// Patients must not have all of these conditions in order to satisfy the filter.
/// </summary>
public string MustNotHaveAllConditions { get; set; }
/// <summary>
/// Gets and sets comma separated condition ids.
/// Patients must have at least one of these conditions in order to satisfy the filter.
/// </summary>
public string MustHaveAtLeastOneCondition { get; set; }
/// <summary>
/// Gets and sets comma separated condition ids.
/// Patients must not have at least one of these conditions in order to satisfy the filter.
/// </summary>
public string MustNotHaveAtLeastOneCondition { get; set; }
My Stored procedure will have four parameters like below.
Eg:
@*MustHaveAll*Conditions = "1,2"
@*MustNotHaveAll*Conditions = "3,4"
@*MustHaveAtLeastOne*Condition = "5,6,7,8"
@*MustNotHaveAtLeastOne*Condition = "9, 10"
I am using a UDF that returns a table with Ids column.
My question:
Basically I can use SQL "IN" operator to find the patients who has at least one Condition (ie : @MustHaveAtLeastOneCondition ) and "NOT IN" operator combination to filter @MustNotHaveAnyConditions.
Are there any SQL Operators(or esay ways) to filter MustHaveAllConditions, MustNotHaveAllConditions parameters ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实没有一种简单的方法可以完成您所描述的操作。我要做的可能是将您的字符串拆分为一个表变量,然后使用右连接、左连接和内连接的组合来从另一个表变量(即我的输出)中删除结果。
There really isn't an easy way to do what you're describing. What I would do is probably take your string and split it into a table variable and then use a combination of right, left and inner joins to remove results from another table variable that was my output.