如果它们以逗号分隔,则使用过滤多个ID(,) [英] use filteration for multiple ID if they are in comma seperated (,)

查看:73
本文介绍了如果它们以逗号分隔,则使用过滤多个ID(,)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何搜索与(,)分开的列。如果FacilityId存在于多列中,那么它将返回完全没有行。



我有列设施包含多个facilityId,如16,17,14,2,10。



例如:



FacilityId 1:16,17,14,2,10

FacilityId 2:6,7,4,2,10

FacilityId 3:5,17,14,20 ,11

FacilityId 4:12,13,14,2,10

FacilityId 5:10,17,12,2,18



如果我用Id 16搜索,那么表将返回1没有行

如果我用Id 10搜索,那么表将返回4没有行

如果我用Id 17搜索,那么表将返回3没有行

如果我用Id 2搜索,那么表将返回4没有行




现在我想用facilityId搜索工具。

How to search a column seperated with (,).If FacilityId is exist in many column then it will return exact no of rows.

I have column Facility that contains multiple facilityId like 16,17,14,2,10.

For Example:

FacilityId 1:16,17,14,2,10
FacilityId 2:6,7,4,2,10
FacilityId 3:5,17,14,20,11
FacilityId 4:12,13,14,2,10
FacilityId 5:10,17,12,2,18

If i searched with Id 16 then table will return 1 no of rows
If i searched with Id 10 then table will return 4 no of rows
If i searched with Id 17 then table will return 3 no of rows
If i searched with Id 2 then table will return 4 no of rows
etc

Now I want to search facility with facilityId.

推荐答案

说真的吗?不要。

将逗号分隔列表转换为整数数组(或其他集合)并使用它。逗号分隔数据很难处理 - 如果它来自数据库,那么更改数据库设计以添加另一个表格,该表格将您的教师交叉引用到您的ID。这将使你的生活变得更加简单。



要更改逗号分隔数据相对简单:

Seriously? Don't.
Convert the commas separated list into an array (or other collection) of integers and use that instead. Comma separated data is a pain to work with - and if it's coming form a database then change the DB design to add another table which cross references your faculty to your ids. It will make your life a lot simpler.

To change the comma separated data is relatively simple:
int[] data = "16,17,14,2,10".Split(',').Select(s => int.Parse(s)).ToArray();

但是你每次你想使用它都必须这样做!从头开始使用整数集合会更简单,更整洁(并且通常更快)。

之后,查看单个集合是否包含特定值也是微不足道的:

But you will have to do that each time you want to use it! It's a lot easier and neater (and generally quicker in the long run) to use a collection of integers to start with.
After that, to see if an individual collection contains a specific value is also trivial:

bool doesItHaveOne = data.Contains(16);



但是......如果数据在数据库中的一个单独的表中,那么完成整个任务就更容易了:SQL就是为那种设计的查询!


But...if the data is in a separate table in the DB, it's even easier to do the whole task: SQL is designed for that kind of query!


这篇关于如果它们以逗号分隔,则使用过滤多个ID(,)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆