So I have an awful query that current exists in MS Access that I am trying to rewrite in SQL Server. Basically I get data that comes from a text file that I am trying to filter down based on specific criteria.
My issues comes in with the way the data is in the text file. My table is similar to this:
Table1
BusinessDate DateTime
Amount money
User1 varchar
User2 varchar
User3 varchar
User4 varchar
... varchar
User16 varchar
I have a data table that has the date and then has 16 columns with a data that has been added by a different user. There are some other fields in this table but they are unnecessary for this question.
The current query does filtering on 15 values where the userId is like something.
SELECT *
FROM Table1
WHERE (User1 Like 'AB%' Or User1 Like 'CD%' Or User1 Like 'EF%'...)
OR (User2 Like 'AB%' Or User2 Like 'CD%' Or User2 Like 'EF%'...)
What I am trying to do is store the like values in a table so I can join on them in my query. I don’t know all of the values so I need to use the wildcard because it could be any possible combination of alphanumeric characters. So I will have a table like this:
ValueTable
AB%
CD%
EF%
HI%
...
Then my query would be something similar to this but I don’t think this is possible
SELECT *
FROM Table1
WHERE User1 Like IN (SELECT Value FROM ValueTable)
OR User2 Like IN (SELECT Value FROM ValueTable)
Is it possible to do something like this? If so, what syntax should be used because I am totally stumped.
Or (2008 syntax)