I need to get the string between the - and the ·, which is the GigabitEthernet1/0/1
CW-3D13-SW1 - GigabitEthernet1/0/1 · Uplink to 1K5-Core1
CW-3D13-SW1 - FastEthernet1/0/43 · PHSA-MPAACT-3D13/16 - Cisco 2811 Fa 0/0
c&w-internet-sw-ACB - GigabitEthernet1/0/24 · MPAACT PNG/UBC School of Medicine
c&w-internet-sw-ACB - GigabitEthernet1/0/25 - Int-Link-CW-BCCA-Oak-St
I can use the following
SUBSTRING(Caption, CHARINDEX(' - ', Caption) + 3, CHARINDEX(' · ', Caption) - CHARINDEX('- ', Caption) + LEN(' · ') - 3)
And it would give me what I want, but there are some instance where the · is replace by the -. For example:
c&w-internet-sw-ACB - GigabitEthernet1/0/25 - Int-Link-CW-BCCA-Oak-St
And this would break my query. Is there a way to satisfy both - and the ·
Thank
Update - Is it possible to add another condition? When string are as bellow:
VPN 3030 - PCI Fast Ethernet
There is no - or · at the end. In this case I just want what ever is after the -
Try this
It's ugly as hell, but I think it does what you need.
To briefly explain, for those where the dot is not a separator/delimiter, reverse the caption and get a substring from the first instance of " - " all the way to the end. Reverse the result of this operation, returning it to the order it was originally and again get the substring from the first instance of " - " to the end.
I created a min function for this.
It just returns the smaller of the two values. Then you can use it to do a RIGHT followed by a LEFT. You can actually put this in a single select statement but splitting it the way I did makes it more readable, in my opinion. Give it a try... hope it works!
The inner select statement gets the all the values RIGHT of the first "-" or "·". Then the outer select will get everything LEFT of the second "-" or "·"
I've edited my code to account for no second "-" or "·"
EDIT: I can't use sqlfiddle since this solution requires a function... but here is what I was able run in my sandbox environment...
and here is the result...
If you can't figure it out from this code... it's time to hit the books mister. ;)