My sql report has lots of inner queries. I have to pass the list of values in where clause. Same values are being passed few times. It takes more than 10 minutes to execute this query. Is there any way to optimise replacing the where condition with array or some other mechanism.
This list of IDs are used multiple times inside the nested queries.
List of IDS= SELECT ID
FROM Employee
where City = 'Berlin'
...............
This is a snippet of my query (not fully copied just wanted to show how I used above list in where conditions)
SELECT Job_id,client_id,details
FROM Clients
where employeedID not in ( ***SELECT ID
FROM Employee
where City = 'Berlin*'**)
where WORKID in (SELECT [WORKID]
FROM Client_projects
where DESCRIPTION in (SELECT [DESCRIPTION]
FROM Projects
where employeedID in (***SELECT ID
FROM Employee
where City = 'Berlin'***)
where taskname = 'Project in Progress'))) and TASKNAME like '%Progress') and description in (SELECT [DESCRIPTION]
FROM Client
where employeeID in (***SELECT ID
FROM Employee
where City = 'Berlin'***
where taskname = 'Project Completed')) and STATUS not in ('Cancelled','Closed')
.........
I tried to create an array to pass the value but couldn't succeed .