In SQL Server, how do you remove everything after a character in a string?
In this example, we will look at how to find everything after a character and then remove the content after the character.
In this example, we are going to look at our IP_List for all entries that contain a colon followed by numbers.
IP Addresses | ID
- 177.91.67.200:42574 | 3938
- 190.80.51.210:33304 | 3939
- 190.5.33.59:10202 | 3940
- 38.196.251.17:36368 | 3941
- 190.122.90.115:37574 | 3942
- 31.57.38.3:50019 | 4134◀
- 31.57.38.3:58797 | 4135◀
In the above list, the last two entries have identical IP addresses but differ in the colon and numbers after it.
This, in turn, will mess with the code that checks whether the IP is listed.
This example will find all records in your database that contain a
colon.
In this example, we will remove the character after the colon.
If you have many rows that contain substrings you need removed, you will have to remove them one by one.