Ben Rapier
asked on
SQL Substring Extraction
I am trying to set two substring values, from an audit table, to respective columns but the solutions I've found pertain more to single character delimiters than substring delimiters. Any guidance and/or suggestions would be great as there are around 30 unique statuses and hundreds of 'from --> to' combinations of statuses.
What I have now (from the audit.audit_text field):
Ticket status has been changed from "In Progress" to "Ready for Dispatch".
Escalation level changed from "Plan" to "Waiting"
Here is what I've tried:
SUBSTRING(dbo.SR_Audit.Aud it_Text, CHARINDEX('to ', dbo.SR_Audit.Audit_Text) + 4, CHARINDEX('. ', dbo.SR_Audit.Audit_Text) - CHARINDEX('to',dbo.SR_Audi t.Audit_Te xt) - 5) AS ChangedTo,
SUBSTRING(dbo.SR_Audit.Aud it_Text, CHARINDEX('from ', dbo.SR_Audit.Audit_Text) + 6, CHARINDEX('to ',
dbo.SR_Audit.Audit_Text) - CHARINDEX('from', dbo.SR_Audit.Audit_Text) - 8) AS ChangedFrom
-----------------
(See attached results)
The ChangedFrom field seems to be OK but the ChangedTo field has some unwanted results.
-----------------
I want to strip the quote marks that surround each status and ignore everything after the first sentence.
Desired alias fields:
Alias Value
ChangedFrom In Progress
ChangedTo Ready for Dispatch
Results1.PNG
What I have now (from the audit.audit_text field):
Ticket status has been changed from "In Progress" to "Ready for Dispatch".
Escalation level changed from "Plan" to "Waiting"
Here is what I've tried:
SUBSTRING(dbo.SR_Audit.Aud
SUBSTRING(dbo.SR_Audit.Aud
dbo.SR_Audit.Audit_Text) - CHARINDEX('from', dbo.SR_Audit.Audit_Text) - 8) AS ChangedFrom
-----------------
(See attached results)
The ChangedFrom field seems to be OK but the ChangedTo field has some unwanted results.
-----------------
I want to strip the quote marks that surround each status and ignore everything after the first sentence.
Desired alias fields:
Alias Value
ChangedFrom In Progress
ChangedTo Ready for Dispatch
Results1.PNG
Can't write any code against a picture of data. Without actual INSERT statements with data, can only guess at the code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the quick answers!