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.
A:
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):
- the brand exists by itself: "brand3"
- the brand starts the delimited field: "brand3|brand4|brand6"
- the brand is in the middle of the field: "brand1|brand3|brand6"
- 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.
Chris Latta
2010-02-12 05:42:59
Thanks Chris i'm developing mobile ordering solution. And my goal is to give invoice discounts to customers. Each item belongs to any brand. Invoice discount rule is would be defined in invoice discount table. For example user by brand1|brand2 and min amount is 10000 then gets 1 percent discount. Brands combination should till 20. I just like to check user collected item against to invoice discount rule. Thanks in advance
Chinggis
2010-02-13 14:57:11