Code for "Does Not Contain" (1 Viewer)

jeff3457

Registered User.
Local time
Today, 17:39
Joined
Oct 30, 2019
Messages
25
I have a union query and I was trying to write a WHERE.... does not contain or does not begin with.

However, I cannot seem to get the syntax of it all correct.

How should I write it?

Thanks!
 

June7

AWF VIP
Local time
Today, 13:39
Joined
Mar 9, 2014
Messages
5,423
Show example data.

Probably something like:

WHERE NOT fieldname LIKE "*sometext*"
 

sonic8

AWF VIP
Local time
Today, 22:39
Joined
Oct 27, 2015
Messages
998
I have a union query and I was trying to write a WHERE.... does not contain or does not begin with.


A union query is two (or more) queries combined together. You either need to repeat the where condition for each of the queries in the union, or you need to wrap all of them into a higher level select statement.

Code:
SELECT Test FROM Table1
WHERE Test NOT LIKE '*AB*'
UNION 
SELECT Test FROM Table2
WHERE Test NOT LIKE '*AB*'
Code:
SELECT * FROM (
    SELECT Test FROM Table1
    UNION 
    SELECT Test FROM Table2
    )
WHERE Test NOT LIKE '*AB*'
 

jeff3457

Registered User.
Local time
Today, 17:39
Joined
Oct 30, 2019
Messages
25
So below is my code.

SELECT [Location], [DeptID], [Name], [ID], [1], [STD Hrs/WK], [1], [Acct Code], [Pay Status], [Eff Date], [Last Start], [Reg/Temp], [Full/Part], [Mail Drop], [Expected Return Date], [Action], [Reason], [Job Code], [Job Code Descr], [Contract #]
From [Support Active Table]
WHERE ([Contract #] <> "")

UNION SELECT [Location], [DeptID], [Name], [ID], [1], [STD Hrs/WK], [1], [Acct Code], [Pay Status], [Eff Date], [Last Start], [Reg/Temp], [Full/Part], [Mail Drop], [Expected Return Date], [Action], [Reason], [Job Code], [Job Code Descr], [Contract #]
From [NBPU List]
WHERE ([Contract #] <> "")

I want to write in my WHERE a does not begin with [Acct Code] '72801011'
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:39
Joined
Feb 28, 2001
Messages
27,001
Is the account code numberic or text? Makes a big difference in how you do this.
 

sonic8

AWF VIP
Local time
Today, 22:39
Joined
Oct 27, 2015
Messages
998
I want to write in my WHERE a does not begin with [Acct Code] '72801011'
What is the problem with that?

June7 addressed that already.

Code:
... WHERE [Acct Code] NOT LIKE '72801011*'
 

jeff3457

Registered User.
Local time
Today, 17:39
Joined
Oct 30, 2019
Messages
25
What is the problem with that?

June7 addressed that already.

Code:
... WHERE [Acct Code] NOT LIKE '72801011*'

Not sure if it was the '*' I was missing or not but it was not cutting them out. Now it is. Thanks.
 

Users who are viewing this thread

Top Bottom