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)
 Parsing specified string from CHAR field

Author  Topic 

umertahir
Posting Yak Master

154 Posts

Posted - 2009-05-15 : 06:02:55
How do I filter my records by picking a specific pattern from my CHAR field?

Field example:
78Or_Or_FFAMF_L
90Or_Or_FF_1990
91Or_Or_FM_1991
86Or_F1X2F0008
81Or_Or_FFAMF_W


I want only those records to be picked which have 'FF' occurring in it.

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-05-15 : 06:11:53
select col1 from table having charindex('FF',col1)>0


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled
Go to Top of Page

umertahir
Posting Yak Master

154 Posts

Posted - 2009-05-15 : 06:16:36
Thanks, I have now put it like this as suggested by you:

SELECT chrBlupID
FROM dbo.tblAnimal
WHERE CHARINDEX('FF',chrBlupID) > 0


quote:
Originally posted by senthil_nagore

select col1 from table having charindex('FF',col1)>0


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

Go to Top of Page

umertahir
Posting Yak Master

154 Posts

Posted - 2009-05-15 : 06:17:08
OR can't i use:
SELECT	chrBlupID
FROM dbo.tblAnimal
WHERE chrBlupID LIKE '%FF%'
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-05-15 : 06:23:11
"Like" may slow down your Query.. Use Where Clause instead of Having


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled
Go to Top of Page

umertahir
Posting Yak Master

154 Posts

Posted - 2009-05-15 : 06:45:28
Thanks for your help.
quote:
Originally posted by senthil_nagore

"Like" may slow down your Query.. Use Where Clause instead of Having


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

Go to Top of Page
   

- Advertisement -