I have an SQL select statement that I cannot quite get working.

Dim SelectStr As String = "SELECT * FROM Appointments WHERE Doctor = '" & ComboBox1.Text & "' AND AptDate = #" & DateTimePicker1.Text & "#"

This works perfect ... however I have 2 more WHERE possibilities ... I would like to include all of the above Appointments where PatientName <> "" OR AddName <> "". Basically I want to retrieve patients in the main appointment slot and in the additional appointment slot (just not the rest of the empty timeslots).

The following line of code I tried that did not work only supplied me with those appointments where PatientName <> "" and totally ignored the AddName <> ""

Dim schedphoneSelectStr As String = "SELECT * FROM Appointments WHERE Doctor = '" & ComboBox1.Text & "' AND AptDate = #" & DateTimePicker1.Text & "# AND PatientName <> "" OR AddName <> "" "

Any help would be appreciated.

Recommended Answers

All 2 Replies

This could be tricky depending on what you really want. If you are trying to group patientname and addname then place a parenthesis around that gorup. The parenthesis turns that group into either a true or false. Without the parethesis, each is its own true or false in the overall statement. Not sure if I am making sense... Dont you also want to change the OR to an AND Try this ... AND (PatientName <> "" AND AddName <> "" )

Add paranthesis and use the OR instead of AND and see if it works...if u r grouping it means it has to fulfill the condition...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.