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
 General SQL Server Forums
 New to SQL Server Programming
 select issue

Author  Topic 

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-11-07 : 13:07:52
Hi.I have a column & and want to select the values from that which are like :
FB0311
Tw0851
NW0528

which means only those that has two letters at the begining & then numbers.
plz help.
thank u

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-11-07 : 13:15:24
This should do it

DECLARE @TABLE Table(Col char(6))

INSERT INTO @table
SELECT 'FB0311' UNION
SELECT 'TW0851' UNION
SELECT 'NW0528' UNION
SELECT 'A12345'


SELECT * FROM @table
WHERE col like '[A-Z][A-Z]%'

Jim
Go to Top of Page

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-11-07 : 13:23:01
thank u :)
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-11-07 : 13:26:17
You're welcome

Jim
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-11-07 : 18:04:40
quote:
Originally posted by jimf

This should do it

DECLARE @TABLE Table(Col char(6))

INSERT INTO @table
SELECT 'FB0311' UNION
SELECT 'TW0851' UNION
SELECT 'NW0528' UNION
SELECT 'A12345'


SELECT * FROM @table
WHERE col like '[A-Z][A-Z]%'
AND col NOT LIKE '__%[^0-9]%'
Jim

Added a small addition if the ending characters are supposed to be numeric.
Go to Top of Page
   

- Advertisement -