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 2000 Forums
 Transact-SQL (2000)
 syntax question

Author  Topic 

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-09-22 : 09:54:40
Hi,

Simple question:

Is there any way to write this in a shorter form:

SELECT fcol like 'X' or fcol like 'Y' or fcol like 'Z'

Maybe something like (which I know it won't work but just to give you an idea what I am looking for)

SELECT fcol like ('X' or 'Y' or 'Z')

Thanx

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-22 : 09:59:39
SELECT fcol FROM MyTable
where
fcol in ('X', 'Y', 'Z')


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-09-22 : 10:05:01
I see the logic but it didn't quite work. It didn't return anything even though there are entries that should be returned. Here is the whole query:

select ftype
from engecnentries
where ftype in ('%cone%','%basin%')
Go to Top of Page

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-09-22 : 10:11:38
I now see why it is failing, but I NEED to make the use of WILD characters
Go to Top of Page

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-09-22 : 11:45:43
anybody??? :-(
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-22 : 13:59:20
You can't use wildcards with IN operator:

select ftype
from engecnentries
where ftype like '%cone%'
or ftype like'%basin%'


But this will be really bad, performance-wise since:

1. You are using % prefix in the condition which will boil down to table scan
2. You need OR condition

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-09-22 : 15:18:14
It looks like you should seriously consider using full-text indexing and queries.

If you don't want to use full-text indexes, then no, there is no easier way than what you had in your original post.
Go to Top of Page

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-09-22 : 15:26:07
since I have never used full-text indexing, I'll have to do some reading before I can comment. Thanx for the advice though
Go to Top of Page

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-09-22 : 17:24:19
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=754544&SiteID=1&mode=1
Go to Top of Page
   

- Advertisement -