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
 Muliti value in like condition

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2013-11-05 : 16:58:20

Im trying to filter the word starts with SAG,WAG,DGA from the table:version of column versiondescription


tablename:version

versionid versiondescription
********** *******************
1 sag buildagreement
2 wag buildagreement
3 dga buildagreement



My existing query:

Declare @GuildFilter varchar(1000)
declare @Guild varchar(1000)
set @Guild='DGA,WGA'
set @GuildFilter= '['+ replace(@Guild,',','-') +']%'


SELECT * FROM version av
where av.versiondescription like '[DGA-WGA]%'



when i try to pass only DGA and WGA,query also picks SGA .can anyone help me out on this?



Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2013-11-05 : 18:42:05
The brackets in a LIKE comparison act as special characters that enclose a set of characters to match. Your LIKE comparison is trying to find any string the begins with 'D' or 'G' or any letter between 'A' and 'W' or 'G' or 'A'. Lookup LIKE in Books Online.

HTH

=================================================
No, no, you're not thinking, you're just being logical. -Niels Bohr
Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2013-11-05 : 21:47:58
I will be passing the parameter like either 'SAG' or 'Wga'or 'DGA'
OR ELSE all the three.based on this my like operator should work.
quote:
Originally posted by Bustaz Kool

The brackets in a LIKE comparison act as special characters that enclose a set of characters to match. Your LIKE comparison is trying to find any string the begins with 'D' or 'G' or any letter between 'A' and 'W' or 'G' or 'A'. Lookup LIKE in Books Online.

HTH

=================================================
No, no, you're not thinking, you're just being logical. -Niels Bohr


Go to Top of Page
   

- Advertisement -