How can I check if my string contains leading letters? In C# is easy, but I am doing this in SQL. Is there a way to check this? If so, how can I remove it?
EX: @MyString = 'A1234'
Updated string = '1234'
The contains() method checks whether a string contains a sequence of characters. Returns true if the characters exist and false if not.
In order to check if a String has only Unicode letters in Java, we use the isDigit() and charAt() methods with decision-making statements. The isLetter(int codePoint) method determines whether the specific character (Unicode codePoint) is a letter. It returns a boolean value, either true or false.
The idea is to use the regular expression ^[a-zA-Z0-9]*$ , which checks the string for alphanumeric characters. This can be done using the matches() method of the String class, which tells whether this string matches the given regular expression.
Use:
UPDATE YOUR_TABLE
SET your_column = SUBSTRING(your_column, 2, DATALENGTH(your_column))
WHERE your_column LIKE '[A-Za-z]%'
For one leading letter, you can do:
IF NOT ISNUMERIC(SUBSTRING(@MyString, 1, 1))
SET @MyString = SUBSTRING(@MyString, 2, LEN(@MyString))
You can repeat that until there are no more letters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With