I have a view qrySearchFields with several tables in it, including
tblCustomer (CustomerID, CustomerName, CustomerPhone)
and
tblCustomerTypeLineItems (CustomerTypeLineItemID, CustomerID, CustomerTypeID)
so if I do a select on the view
SELECT * FROM qrySearchFields WHERE CustomerTypeID = '33'
returns
123,'Freds garage','5555554432',442,123,33
341,'Bills Automotive','5455553562',445,341,33
I'll get a list of customers with that type. great!
however, where I run into problems is that some customers have multiple types, so if I
SELECT * FROM qrySearchFields WHERE CustomerID = '123'
SELECT * FROM qrySearchFields WHERE CustomerID = '341'
I'll get
123,'Freds garage','5555554432',442,123,33
123,'Freds garage','5555554432',443,123,66
341,'Bills Automotive','5455553562',445,341,33
341,'Bills Automotive','5455553562',446,341,41
which is ok, unless I want to exclude by customer type
SELECT * FROM qrySearchFields WHERE CustomerTypeID = '33' AND NOT CustomerTypeID = '66'
still returns
123,'Freds garage','5555554432',442,123,33
341,'Bills Automotive','5455553562',445,341,33
while customer 123 should be excluded since its also type '66'.
SO...
What I think I need to do is to somehow join tblCustomerTypeLineItems to itself so that it'll check every line where customerID is 123 and exclude it if any of them are 66...
I just dont know how to do this, especially in a view.
Anyone? thanks in advance
tblCustomer (CustomerID, CustomerName, CustomerPhone)
and
tblCustomerTypeLineItems (CustomerTypeLineItemID, CustomerID, CustomerTypeID)
so if I do a select on the view
SELECT * FROM qrySearchFields WHERE CustomerTypeID = '33'
returns
123,'Freds garage','5555554432',442,123,33
341,'Bills Automotive','5455553562',445,341,33
I'll get a list of customers with that type. great!
however, where I run into problems is that some customers have multiple types, so if I
SELECT * FROM qrySearchFields WHERE CustomerID = '123'
SELECT * FROM qrySearchFields WHERE CustomerID = '341'
I'll get
123,'Freds garage','5555554432',442,123,33
123,'Freds garage','5555554432',443,123,66
341,'Bills Automotive','5455553562',445,341,33
341,'Bills Automotive','5455553562',446,341,41
which is ok, unless I want to exclude by customer type
SELECT * FROM qrySearchFields WHERE CustomerTypeID = '33' AND NOT CustomerTypeID = '66'
still returns
123,'Freds garage','5555554432',442,123,33
341,'Bills Automotive','5455553562',445,341,33
while customer 123 should be excluded since its also type '66'.
SO...
What I think I need to do is to somehow join tblCustomerTypeLineItems to itself so that it'll check every line where customerID is 123 and exclude it if any of them are 66...
I just dont know how to do this, especially in a view.
Anyone? thanks in advance