views:

428

answers:

1

Hello,

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...

A: 

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...

gbn
Yeah, I can use a CLR function or the LIKE, I still don't know how to do it.For example, how you I know if the range 12345678912-1900000000 possibly overlaps the wildcard "1*98*9??" ? (number 122982123959 for example overlaps)
Kevin
Now you given that more complex example, I'd guess LIKE/CAST would work for single ? anywhwere with 123% or %123 types only. I say "possible" because things are rarely "impossible" but I wouldn't like to try...
gbn