[Cialug] SQL Question

Todd Walton tdwalton at gmail.com
Tue Oct 6 14:23:01 CDT 2009


SELECT		TOP (1) Date
FROM		SALES.SaleDetails
WHERE		([Action ID] = 'CUST_CONTACT')
ORDER BY	Date

I have the above basic query.  When a sales person processes a lead
they put the information into the sales tracker program.  So, the
"lead" is opened.  I want my sales people contact the potential
customer within a certain time period after opening the lead.  When
they do that they log it in the program, which creates a
"CUST_CONTACT" line in the database.  This query pulls back the most
recent CUST_CONTACT date.

The problem is, the sales person may contact the customer, make the
sale, and then just close the lead and not bother to put in a contact
entry.  So, I want to modify the above to ask, "What is the most
recent CUST_CONTACT date, or CLOSED date if there is no CUST_CONTACT
entries?"  I want to use the CUST_CONTACT date if it's available, but
use CLOSED if there is no CUST_CONTACT.

Anyone got a suggestion?

--
Todd


More information about the Cialug mailing list