June 29, 2016 at 7:29 am
I have a change log record that records address changes. Many of these changes are the result of address standardization. I'd like to exclude records that are only zip + 4 changes.
This is the pattern of the text:
Name.FULL_ADDRESS: street address city, ST zip + 4 -> street address city, ST zip
The zip + 4 includes the dash, the zip would only have 5 digits.
I'm guessing my string comparison needs to compare everything after Name.FULL_ADDRESS: up to '->' to everything after '->' where the last 10 characters don't include '-' ?
This is my script to extract multiple changes for the past month.
SELECT ID, COUNT(ID) AS CountofChanges, LOG_TEXT
FROM NameLog
WHERE
(LOG_TEXT LIKE 'Name.FULL_ADDRESS:%')
AND (DATE_TIME >= DATEADD(month, - 1, GETDATE()))
GROUP BY ID, LOG_TEXT
HAVING (COUNT(ID) > 1)
Can anyone push me in the right direction?
June 29, 2016 at 9:24 am
Full address is in a single field? That might cause you problems.
If you had zip code/postal code in its own field, you could add a trigger on the table's zip code column... then you could compare the original value and the new value
if left(deleted.zipcode,5)!=inserted.zipcode then
... log it
end if
June 29, 2016 at 9:56 am
It looks to me like you'll need to extract a sub-string of the Full Address that excludes any Zip+4 value.
You can do that with PatIndex and SubString functions.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply