Tuesday, 15 January 2013

sql - TSQL - Partial Matching using LIKE for multiple values -



sql - TSQL - Partial Matching using LIKE for multiple values -

i seek advice whether function in sql server allow me perform partial matching list of values ?

the entire string need matched passed in via store procedure.

i trying find other alternative before writing own function split string comma , union results before homecoming info program.

for example, pass in next string tsql

apple,orange,pear

in where clause should match

select * store fruits 'apple%' select * store fruits 'orange%' select * store fruits 'pear%'

can accomplish above results in single sql statement rather writing function break each string ?

data in table

apple reddish apple greenish orange sweetness orange sour pear big pear little

so, when passed in string "apple,pear" , need homecoming

apple reddish apple greenish pear big pear little

try this, performance not great

declare @parm varchar(200) set @parm = ','+'apple,orange,pear'+',' select * store charindex(fruit,@parm) > 0

sql sql-server tsql

No comments:

Post a Comment