Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 expression matching

Author  Topic 

Ratz03
Starting Member

27 Posts

Posted - 2015-02-05 : 11:35:40
Source Table
Policy Number
12345678908
98765432134
bghtyukn765
kjkjjkiumlo
12345678uyt
98765678ooo

i want only policies that follow format of first eight chars are alphbet and next 3 digits to be in my output.

I have tried using the substring, like, charindex functions but it's not working. Please suggest how this can be done.

Thanks


Ifor
Aged Yak Warrior

700 Posts

Posted - 2015-02-05 : 11:45:28
[code]
-- *** Test Data ***
CREATE TABLE #t
(
Policy_No varchar(20) NOT NULL
);
INSERT INTO #t
VALUES ('12345678908'), ('98765432134'), ('bghtyukn765')
,('kjkjjkiumlo'), ('12345678uyt'), ('98765678ooo');
-- *** End Test Data ***

SELECT *
FROM #t
WHERE Policy_No LIKE '[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][0-9][0-9][0-9]';
[/code]
Go to Top of Page
   

- Advertisement -