Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to pre-filter data in SQL Server

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-11-16 : 09:51:28
Ahmed Khan writes "I need to query the Employees table in the ABC database to find all employees who report to EmployeeID 5 (indicated by a value of 5 in the ‘ReportsTo’ column) and who have the word ‘Sales’ in their job title (i.e the Title column). In my database the Employees table is very large so you want to pre-filter the data before doing more complicated processing on it. How would I use the following statement to to pre-filter the data?

SELECT * FROM EMPLOYEES WHERE ReportsTo = 5

Many thanks"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-11-16 : 09:55:02
[code]Create Table #EmpTemp
(
....
)

Insert into #EmpTemp
Select *
from EMPLOYEES WHERE ReportsTo = 5 and Title = 'Sales'

-- do further processing on #EmpTemp
[/code]

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2006-11-16 : 18:15:30
I haven't read the question properly but buy the sounds of it a Self Join springs to mind.
Go to Top of Page

MichelleMA
Starting Member

32 Posts

Posted - 2006-11-16 : 20:17:52
If the title has the word Sales and not exactly Sales, I would do:

Select * from EMPLOYEES
WHERE ReportsTo = 5 AND Title like '%Sales%'
Go to Top of Page
   

- Advertisement -