简体   繁体   中英

Count Specific Words in a string

Need your assistance please. I need to write a query to count the number of times the word 'user' appears in the below string.

I'am currently using the below select query however the counts are not accurate.

(len(CallEventLog) - len(replace(CallEventLog, 'user',' ')))/ len('user') as #ofTransfers_Users

09:06:56: Initializing 09:06:56: Offering 09:06:56: ANI: 33327368876 09:06:56: DNIS: 7885 09:06:56: Call answered 09:06:56: Call entered IVR: CF1Residential 09:06:57: IVR: CF1Residential 09:07:41: Offering 09:07:41: Entered Workgroup ACDNewMoving 09:07:41: ACD - Wait Agent 09:08:33: ACD interaction assigned to kmara 09:08:33: Offering 09:08:33: Sent to user kmara 09:08:35: Connected 09:08:35: Sent to station GPD6T5432S 09:08:35: ACD interaction connected to kmara 09:08:35: ACD - Assigned: kmara 09:09:40: Held 09:12:33: Connected 09:12:33: Entered Workgroup ACDMetering 09:12:33: Sent to user fwinger 09:14:16: Disconnected [Local Hang Up] 09:14:16: Local Disconnect

Thanks

The problem with your query is that you are replacing the value 'user' with a space character, but it should be an empty string. So instead of:

(len(CallEventLog) - len(replace(CallEventLog, 'user',' ')))/ len('user') as #ofTransfers_Users

do this:

(len(CallEventLog) - len(replace(CallEventLog, 'user','')))/ len('user') as #ofTransfers_Users

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM