如何使用 SQL Server 处理多个通配符
我有一些以下形式的过滤器:
对象 A
+/- Start End
----------------------------------------------
+ 000000080000 000000090000
- 000000800500
+ 054*
对象 B
+/- Start End
----------------------------------------------
+ 000000090000 000000100000
+ 00??00900500
- 000000900500
+ 055*
它的意思是:
0000000800500 之外的 000000080000 和 000000090000 之间的数字,以 054 开头的数字与对象 A 关联。000000090000
和 000000100000 之间的数字(000000900500 除外),数字匹配00??00900500 (当然除了 000000900500),以 055 开头的数字与对象 B 关联。
表结构示例:
CREATE TABLE dbo.Filter
(
IDFilter int IDENTITY PRIMARY KEY
)
CREATE TABLE dbo.FilterRow
(
IDFilterRow int IDENTITY PRIMARY KEY
,IDFilter int FOREIGN KEY REFERENCES dbo.Filter(IDFilter) NOT NULL
,Operator bit --0 = -, 1 = + NOT NULL
,StartNumber varchar(50) NOT NULL
,EndNumber varchar(50)
)
CREATE TABLE dbo.[Object]
(
IDObject int IDENTITY PRIMARY KEY
,Name varchar(10) NOT NULL
,IDFilter int FOREIGN KEY REFERENCES dbo.Filter(IDFilter) NOT NULL
)
我需要一种方法来确保在 SQL(或 CLR)中没有数字可以与超过 1 个对象关联,并且我真的不知道如何做这样的事情(除了暴力)。
我确实有一个 CLR 函数 Utils.fIsInFilter('?8*', '181235467895') 支持通配符,如果有帮助的话会返回 1...
I have some filters in the following form:
Object A
+/- Start End
----------------------------------------------
+ 000000080000 000000090000
- 000000800500
+ 054*
Object B
+/- Start End
----------------------------------------------
+ 000000090000 000000100000
+ 00??00900500
- 000000900500
+ 055*
It means:
Numbers between 000000080000 and 000000090000 except 000000800500, and numbers starting with 054 are associated with object A.
Numbers between 000000090000 and 000000100000 except 000000900500, numbers matching 00??00900500 (except 000000900500 of course), and numbers starting with 055 are associated with object B.
Example of the table structure:
CREATE TABLE dbo.Filter
(
IDFilter int IDENTITY PRIMARY KEY
)
CREATE TABLE dbo.FilterRow
(
IDFilterRow int IDENTITY PRIMARY KEY
,IDFilter int FOREIGN KEY REFERENCES dbo.Filter(IDFilter) NOT NULL
,Operator bit --0 = -, 1 = + NOT NULL
,StartNumber varchar(50) NOT NULL
,EndNumber varchar(50)
)
CREATE TABLE dbo.[Object]
(
IDObject int IDENTITY PRIMARY KEY
,Name varchar(10) NOT NULL
,IDFilter int FOREIGN KEY REFERENCES dbo.Filter(IDFilter) NOT NULL
)
I need a way to make sure no numbers can get associated with more than 1 object, in SQL (or CLR), and I really have no clue how to do such a thing (besides bruteforce).
I do have a CLR function Utils.fIsInFilter('?8*', '181235467895') that supports wildcards and would return 1, if it helps...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以在 SQL 2005 中使用 CLR 函数吗?
在原始 SQL 中可以使用 LIKE JOINS(其中 ? 变成 [0-9],* 变成 %),也许后面跟着 CAST,但这就是 CLR 函数的用途……
Can you use a CLR function in SQL 2005?
It's possible in raw SQL using LIKE JOINS (where ? becomes [0-9] and * becomes %), perhaps followed by CAST, but this is what CLR functions are for...