Remove invalid data based on particular pattern SQL Server -
i have sample data shown below
------------------------------------------------ | id | column 1 | column 2 | ------------------------------------------------ | 1 | 0229-10010 |valid | ------------------------------------------------ | 2 | 20483 |invalid | ------------------------------------------------ | 3 | 319574r06-stat |valid | ------------------------------------------------ | 4 | ,,,,,,,,,,,,,,1,,,,,,, |invalid | ------------------------------------------------ | 5 | "pbom-sse, chamber" |valid | ------------------------------------------------ | 6 | ""pbom-sse, chamber |invalid | ------------------------------------------------ | 7 | "pbom-sse chamber", |invalid | ------------------------------------------------ | 8 | #drm-1102.z |invalid | ------------------------------------------------ | 9 | drm#1102.z |valid | ------------------------------------------------ | 10 |oem-2-202 4079 kalrez |valid | ------------------------------------------------ | 11 |-oem2202 4079 kalrez# |invalid | ------------------------------------------------
what want need create pattern in such way need fetch invalid data. representation have mentioned valid , invalid. in table don't have flag such.
here trick same, wildcard character
s appearing @ different places makes different sense. consider record id-5
, id-6
. in both cases wildcard characters same, position decides whether valid or not. again position not clear. guess can make out why particular record in column 1 valid , invalid. in record 8
, '#'
before item doesn't makes sense, # after alphabet makes sense (in record 9).
in record 2, there lot of blank spaces before number, that's why invalid, doesn't mean space wild card. have written query below.
select [partnumber] [ibsssystems].[dbo].[part] (partnumber '%[?;.,$^@&*{}:"<>/|\ %'']%' or partnumber '%[%' or partnumber '%]%')
the above query understands whenever see wildcard character in record , fetches that. need query in such way understands , fetches invalid data. guess there lot of and
, or
in resulting query, i'm confused. hope can me out. in advance.
select [partnumber] [ibsssystems].[dbo].[part] (partnumber '[^a-za-z0-9"]%' escape '\' -- when first character special charater invalid ( " exception) or partnumber '%[^a-za-z0-9" ]' escape '\' -- when last character special charater invalid ( " exception, trailing spaces exception) or partnumber '%[^a-za-z0-9 ][^a-za-z0-9 ]%' -- when there 2 or more consecutive special charaters invalid or partnumber '%[\^\[\]\\_?;$@&*{}:<>/|''~`]%' escape '\' -- add characters here not allowed have occurrence in string )
Comments
Post a Comment