Consider the following table :
create table mixedvalues (value varchar(50)); insert into mixedvalues values ('100'), ('ABC100'), ('200'), ('ABC200'), ('300'), ('ABC300'), ('400'), ('ABC400'), ('500'), ('ABC500');
How can I write a select statement that would only return the numeric values like
100 200 300 400 500
In SQL Server, we can use the ISNUMERIC() function to return numeric values from a column. We can alternatively run a separate query to return all values that contain numeric data.
Syntax to check if the value is an integer. select yourColumnName from yourTableName where yourColumnName REGEXP '^-?[0-9]+$'; The query wherein we have used regular expression. This will output only the integer value.
As the name suggests, varchar means character data that is varying. Also known as Variable Character, it is an indeterminate length string data type. It can hold numbers, letters and special characters.
SELECT * FROM mixedvalues WHERE value REGEXP '^[0-9]+$';
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