开发者

Complicated condition

开发者 https://www.devze.com 2022-12-20 03:02 出处:网络
I have predefined item combination (for example brand1|brand2|brand3etc) in the table. i like to collect brands开发者_开发百科 and check against with predefined table data.

I have predefined item combination (for example brand1|brand2|brand3 etc) in the table. i like to collect brands开发者_开发百科 and check against with predefined table data. For example i collected brand1|brand2|brand3 then i can do get some value form that predefined table(it meets the condition). How can i check? brands would be unlimited. also brand1|brand2|brand3 of brand1|brand2| exist then returns true.


Okay, taking a wild guess at what you're asking, you have a delimited field with brands in them separated by a | character. You want to return any row that has the right combination of the brands in there, but don't want to return rows with, for example, brand "testify" in them when you search for "test".

You have four search conditions (looking for brand3):

  1. the brand exists by itself: "brand3"
  2. the brand starts the delimited field: "brand3|brand4|brand6"
  3. the brand is in the middle of the field: "brand1|brand3|brand6"
  4. the brand is at the end of the field: "brand1|brand2|brand3"

so, in SQL:

SELECT *
FROM MyTable
WHERE BrandField = 'brand3'
   OR BrandField LIKE 'brand3|%'
   OR BrandField LIKE '%|brand3|%'
   OR BrandField LIKE '%|brand3'

Repeat as required for multiple brands.

0

精彩评论

暂无评论...
验证码 换一张
取 消