Sorry for the NUBE question
I need to build a select statement where a column contains any of many possible values
I think I can create multiple lines like this but, I think there is a more efficient way to do it, especially because I have 30 variables
select * from COMPANY
where
contains (PRODUCTS, "Product1")
or
contains (PRODUCTS, "Product2")
or
contains (PRODUCTS, "Product3")
or
contains (PRODUCTS, "Product4");
This may be what you are looking for .
SELECT *
FROM COMPANY
WHERE PRODUCTS IN ( 'Product1', 'Product2', 'Product3', 'Product4' );
January 15, 2021 at 9:08 am
contains (PRODUCTS, 'Product1 OR Product2 OR Product3 OR Product4 OR ...')
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
January 15, 2021 at 1:02 pm
what on earth is contains, ive never seen that used before
mom pick me up im scared
I want to be the very best
Like no one ever was
January 15, 2021 at 1:17 pm
Thank you @desnorton and @scottpletcher. These both work. Exactly what I was looking for
January 15, 2021 at 3:19 pm
FULLTEXT indexing/search: https://docs.microsoft.com/en-us/sql/t-sql/queries/contains-transact-sql?view=sql-server-ver15
January 18, 2021 at 9:01 pm
lol Me too! But it's got great documentation: https://docs.microsoft.com/en-us/sql/t-sql/queries/contains-transact-sql?view=sql-server-ver15
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply