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 2005 Forums
 Transact-SQL (2005)
 filtering query question

Author  Topic 

sternaphile
Starting Member

5 Posts

Posted - 2007-07-02 : 14:48:41
In a query that I have, I need to return a varchar field that matches a specific pattern, but only that pattern. For instance, if there are three records in the table such that
Record1: TargetField = 'abc123'
Record2: TargetField = 'abcd123'
Record3: TargetField = 'abc1234'

and i try to do this:

set @Symbol = 'abc'
SELECT * from TableA where TargetField like @Symbol + '%[0123456789]'

I get back all three records, when I only want to get back Record1 & Record3. How can this be accomplished to only return Record1 & Record3?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-02 : 14:55:05
set @Symbol = 'abc'
SELECT * from TableA where TargetField like @Symbol + '[0-9]%'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sternaphile
Starting Member

5 Posts

Posted - 2007-07-02 : 15:58:41
Thx Peso; that did it
Go to Top of Page
   

- Advertisement -