简体   繁体   English

如何检查数据是否存在于 SQL Server 表列中,其中数据以引号重新插入

[英]How to check if a data is present in SQL Server table column where the data re inserted in inverted commas

I have added some data values as 'a','b','c' (same as this) in a SQL Server table column.我在 SQL Server 表列中添加了一些数据值作为“a”、“b”、“c”(与此相同)。 How can I check if a or b or c is present in this table value or not?如何检查此表值中是否存在 a 或 b 或 c?

Assuming that your column value looks like:假设您的列值如下所示:

[YourColumn]
-------------
'a','b'
'a'
'a','b','c' 

The following should work:以下应该工作:

SELECT * FROM [YourTable] WHERE Contains([YourColumn], 'a') 
OR
SELECT * FROM [YourTable] WHERE [YourColumn] LIKE '%a%'

However, unless the possible values for this column are very-very excessive, it is not recommended to store them like this in a single column.但是,除非此列的可能值非常非常多,否则不建议将它们像这样存储在单个列中。 Instead, have different flag columns for each value.相反,每个值都有不同的标志列。 Again, do it only if the possible values are limited.同样,仅当可能的值有限时才执行此操作。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM