I am trying to retrieve data from a table where there are codes for projects which are identified by the first three numbers, the rest are unique. So, for example, the query is:
SELECT * FROM
TableA
WHERE LEFT(acccode,3) IN ('121','131','141','151','161')
Now, I want this condition to be true for all these codes except for one. Say, for the first one, I want it to look four more characters for anything like '121-111%'. How can I alter my IN
operator there or do I have to just go with a LIKE
operator with something like:
SELECT * FROM
TableA
WHERE acccode LIKE '121-111%'
OR acccode LIKE '131%'...
and so on...?
To clarify: codes starting with 121-111, 131, 141, 151, 161 are the ones I want to select.
All columns are nvarchar
.