Search code examples
sqlsql-serversql-like

(Microsoft SQL Server Management Studio 17) AND / LIKE operators greyed out


I'm having issues using AND / LIKE operators in select queries.

They seem to be greyed out, and, for instance, when executing a SELECT query that has one or the other, or both included, no records are generated, even though records do exist within the database.

I have tried checking permissions, restarting the database instance - not really sure how to proceed at this point.

Assistance will be greatly appreciated. Many Thanks.

example

EDIT:

Example 1 - As you can see, this query shows two joined tables, which gives me relevant records:

example1

Example 2 - Once I specify the date using the AND Operator, and re-run the query, no records are generated, like none exist. This is the issue I'm experiencing.

example2


Solution

    1. There is not problem that LIKE predicate is grayed, I have this too.

    2. You has define a two mutually exclusive conditions in the AND operator in your WHERE predicate - surely this will not work. You need an OR operator between mutually exclusive conditions in your predicate, like

      WHERE <first predicate>
        AND (Appointment.AppointmentDateTime ='20181102 10:00:00.000' OR 
             Appointment.AppointmentDateTime = '20181105 16:00:00.000')