Could anyone help me to write this more elegantly so it uses the IN statement to represent OR
DECLARE @patient1 int, @patient2 int, @patient3 int
Set @patient1=123, patient2=456, patient3=678
WHERE PATIENT_ID=@patient1 OR PATIENT_ID=@patient2 OR PATIENT_ID=@patient3
So ideally I would like to have the WHERE statement written like this :-
WHERE PATIENT_ID IN(@patient1, @patient2, @patient3)
Should the IN statement work ok like this, with variables in? Also sorry for not showing the error I got but just peoples opinion is fine if anyone can help please.
Also please forgive if there any slight syntax error above as I'm doing this example from memory (from when I was at work.
Ps Could anyone recommend a way of being able to enter as many patient numbers as I like to declare them at the top of the SQL (and in the WHERE clause) without having to amend the code too much everytime I want to search for more patients numbers. Would
I have to use the WHILE statement with arrays maybe - I have no idea with arrays in SQL if anyone can give me some pointers.
View Complete Post