使用WHERE子句查找特定数据类型

时间:2020-12-19 16:58:49

I am trying to find a way to query for a field that only contains a certain data type.

我试图找到一种方法来查询只包含某种数据类型的字段。

For example, I want to return all values from dbo.tableA.ColumnA that contain a string of '___-___' where each _ is a numeric character. (The - is just a normal dash)

例如,我想从dbo.tableA.ColumnA返回包含字符串'___-___'的所有值,其中每个_都是数字字符。 ( - 只是一个正常的破折号)

Also, I know this can be done using dynamic queries (which I am not experienced with) and I am aware that those high level queries probably require the creation of temp tables, which is something I can not do because I am only querying a snap-shot, and thus do not have Write access.

另外,我知道这可以使用动态查询(我没有经历过)来完成,我知道那些高级查询可能需要创建临时表,这是我无法做到的,因为我只是查询快照 - -shot,因此没有写访问权限。

I have tried searching my pants off for an answer, with no luck. Please help. Thank you.

我试着找我的裤子寻找答案,没有运气。请帮忙。谢谢。

1 个解决方案

#1


5  

You can use the LIKE operator for this.

您可以使用LIKE运算符。

SELECT ColumnA 
FROM dbo.tableA
WHERE ColumnA LIKE '%[0-9][0-9][0-9]-[0-9][0-9][0-9]%'

#1


5  

You can use the LIKE operator for this.

您可以使用LIKE运算符。

SELECT ColumnA 
FROM dbo.tableA
WHERE ColumnA LIKE '%[0-9][0-9][0-9]-[0-9][0-9][0-9]%'