If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Pick M or O but not both!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-03, 11:27
130213 130213 is offline
Registered User
 
Join Date: Oct 2003
Posts: 58
Pick M or O but not both!

Hi,

I am still struggling with this query which should pick M or O but not both!


SELECT First(Centre.ECDL_ID) AS FirstOfECDL_ID, [Title] & " " & [Forename] & " " & [Surname] AS Contact, Centre.centrename, Centre.address1, Centre.address2, Centre.town, Centre.county, Centre.postcode, CentreContact.EMail, CentreContactType.CentreContactType

FROM ((Centre INNER JOIN CentreContact ON Centre.CentreID = CentreContact.CentreID) INNER JOIN CentreStatus ON Centre.StatusID = CentreStatus.StatusID) INNER JOIN CentreContactType ON CentreContact.CentreContactTypeID = CentreContactType.CentreContactTypeID

GROUP BY [Title] & " " & [Forename] & " " & [Surname], Centre.centrename, Centre.address1, Centre.address2, Centre.town, Centre.county, Centre.postcode, CentreContact.EMail, CentreContactType.CentreContactType, CentreStatus.Status, Centre.OMR

HAVING (((CentreContactType.CentreContactType)="M" Or (CentreContactType.CentreContactType)="0") AND ((CentreStatus.Status)="AD") AND ((Centre.OMR)=-1))

ORDER BY First(Centre.ECDL_ID);


I tried the UNION query but it still included both Contacts from the same Centre whose CentreContactType’s were M and O, I want to say if M exists show M but if BOTH M and O exist at the same Centre show O instead of M.

Any help woul be very appreciated.

Jnr.
Reply With Quote
  #2 (permalink)  
Old 10-13-03, 15:59
Bart71 Bart71 is offline
Registered User
 
Join Date: Oct 2003
Location: Germany - Stuttgart
Posts: 14
Hi,

did you try the

select case when
from...-statement

select case
when value = 'M'
then 'M'
when value = 'O' or 'M'
then 'o'
from...
where....
Reply With Quote
  #3 (permalink)  
Old 10-14-03, 04:24
130213 130213 is offline
Registered User
 
Join Date: Oct 2003
Posts: 58
Thanks, i will try that.....

its really bugging me!

Jnr
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On