'SQL Regex for 7 digit number in varchar field
Question: What's the best way to 'extract' all Rows where the TEXT column contains a 7 digit number starting with 7 and only show the 7 digit number?
SQL Server 2017:
CREATE TABLE [TABLE_1] (
TEXT varchar(50) Null,
);
INSERT INTO TABLE_1
(TEXT)
VALUES
('7005011'),
('The Number is 7335022'),
('asd*.-: wqe'),
('/7225033/.123'),
('Nr.: 7115044')
;
The desired result would be:
+---------+
| TEXT |
+---------+
| 7005011 |
| 7335022 |
| 7225033 |
| 7115044 |
+---------+
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
