Author |
Topic |
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2008-09-22 : 16:51:56
|
Hi I have a field called customer history where the data is stored in this way----11000000 or -00022122122.i don't want to show the record that contain 3 1's in it(ex ----11001000) or any integer that is greater than 1(ex:-00022122122).How do i filter those records.Thanks |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-23 : 00:14:47
|
WHERE LEN(Col1) - LEN(REPLACE(Col1, '1', '')) <> 3 E 12°55'05.63"N 56°04'39.26" |
 |
|
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2008-09-23 : 15:28:05
|
thanks for the respone but it did not help.Is there something else i need to add to that. |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-09-23 : 18:15:34
|
Does this work or do you have some other requirements or data that you need to handle?DECLARE @Yak TABLE (Col1 VARCHAR(20))INSERT @YakSELECT '----11000000'UNION ALL SELECT '-00022122122'UNION ALL SELECT '-00020122122'UNION ALL SELECT '-00021122122'SELECT *FROM @YakWHERE LEN(Col1) - LEN(REPLACE(Col1, '1', '')) <> 3 AND CAST(REPLACE(Col1, '-', '') AS INT) < 22122122 |
 |
|
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2008-09-24 : 09:50:21
|
it can also have digit 3 in the customer history field. The example is just an random one i picked.thanks for the response though! |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-24 : 10:51:09
|
How about you tell us the full story? E 12°55'05.63"N 56°04'39.26" |
 |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-09-24 : 11:43:22
|
I don't need the full story to throw darts in the dark How about this?filters out any value with 3 or more occurances of any single numeric digit (besides 0)declare @s varchar(155)set @s = '-00022122122'declare @t table (s varchar(200))insert @t (s)SELECT '----11000000'UNION ALL SELECT '-00022122122'UNION ALL SELECT '-00020122122'UNION ALL SELECT '-00021122122'UNION ALL SELECT '-0001234567899999'UNION ALL SELECT '-0001234567899'select t.sfrom @t tcross apply ( select case when exists ( select d.c ,count(*) from ( select n.number ,substring(t.s, n.number, 1) c from master..spt_values n where n.type = 'p' and n.number > 0 and n.number <= len(t.s) ) d where d.c like '%[1-9]%' group by c having count(*) > 3 ) then 1 else 0 end HasMoreThan3 ) cawhere ca.HasMoreThan3 = 0output:s ---------------------------------11000000 -0001234567899 Be One with the OptimizerTG |
 |
|
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2008-09-24 : 16:14:05
|
i am sorry .May be i was not clear.What I need is to filter the string that 1)if the string has more 3 or more than 3 occurences of interger 1 in itex: 10010010 or 1111000 or 11001100 etc2)if the string contains atleast one integer greater than 1ex 000021000, 0330000,0112000 etci want to filter out those strings . hope i am clear this time.i only want records that have 0's and 1's in the string but not more than three 1's |
 |
|
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2008-09-24 : 16:15:00
|
quote: Originally posted by akpaga i am sorry .May be i was not clear.What I need is to filter the string that 1)if the string has 3 occurrences or more than 3 occurrences of interger 1 in itex: 10010010 or 1111000 or 11001100 etc2)if the string contains atleast one integer greater than 1ex 000021000, 0330000,0112000 etci want to filter out those strings . hope i am clear this time.i only want records that have 0's and 1's in the string but not more than three 1's
|
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-24 : 16:38:20
|
WHERE Col1 NOT LIKE '%[^01]%' AND Col1 NOT LIKE '%1%1%1%1%' E 12°55'05.63"N 56°04'39.26" |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-24 : 16:51:37
|
WHERE Col1 NOT LIKE '%[^01]%' AND Col1 NOT LIKE '%' + REPLICATE('1%', 4) E 12°55'05.63"N 56°04'39.26" |
 |
|
|