Do not use on any
shared computer
September 5, 2008 04:18pm pdt
 
[x]
Attachment Details

Retrieving Last Record (SQL)

Tags: MySQL, SQL
Dear EE community,

I've tried searching this site and Google for related solutions although I have yet to find one that works for me. So it's just as easy to write a new question I guess.

The system is for Telesales Out Calling. The .asp page retrieves a list of all customers based on an entered Part Code (product.Product_Code IN '"&SPartCodes&"'.......) and then displays them alphabetically, with their telephone no, date of last order, creation date of note and the call back category of the note.

The categories for call backs are:

<% If pm.GetItem ("CallBackStatus") = "1" Then Response.Write("01 not in") Else
If pm.GetItem ("CallBackStatus") = "2" Then Response.Write("02 call back later today") Else If ..................................<snip>
"3" = 03 call back tomorrow
"4" = 04 call back next week
"5" = 05 call back in a month
"6" = 06 call back in two months
"7" = 07 call back on another date
"8" = not interested / didn't buy
"9" = do not call again
"10" = order made

 End If %>


Now, pretty self explanatory I'm sure as to what the system is doing. Nonetheless, I'm trying to get SQL to retrieve the latest record for a particular call back back status. I can't use Max, as that would only display the higher number. And Top 1 doesn't work either because the SQL query is nested in the asp page.

Also, it's important to mention that ALL notes have a NoteID. Reckon I should exploit this in any way?

Thanks in advance.

Luke, Bentham LTD t/a Inkjets & Toners


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
----------
SQL
----------
(simplified to make it easier to read)
 
SELECT ijtd_export.cart.Customer_URN
       ijtd_export.customer.Customer_Title
       ijtd_export.customer.Customer_Forename
       ijtd_export.customer.Customer_Surname
       ijtd_export.customer.Customer_Telephone
    max(ijtd_export.cart.Cart_Order_DateTime)
    max(outcall.callnotes.CreatedDate)
       outcall.callnotes.CallBackStatus
 
FROM ijtd_export.cart
 
JOIN ijtd_export.cartitem ON ijtd_export.cartitem.Cart_URN = ijtd_export.cart.Cart_URN
 
JOIN ijtd_export.customer ON ijtd_export.cart.Customer_URN = ijtd_export.customer.Customer_URN
 
JOIN ijtd_export.product ON ijtd_export.product.Product_URN = ijtd_export.cartitem.Product_URN
 
LEFT JOIN outcall.callnotes ON outcall.callnotes.Customer_URN = ijtd_export.customer.Customer_URN
 
 
WHERE
 
cart.Cart_Order_DateTime BETWEEN '"&IncStartDate&"' AND '"&IncEndDate&"' AND
cart.Cart_Status = 'Order' AND
product.Product_Code IN '"&SPartCodes&"' AND
cart.Cart_Order_Group = '1' AND
NOT Customer_Surname LIKE '' AND
NOT Customer_Marketing LIKE 'DEAD' AND
NOT Customer_Telephone_Prefs LIKE 'Do not call'
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Database
Question Asked By: BenthamLtd
Solution Provided By: mark_wills
Participating Experts: 2
Solution Grade: A
Views: 121
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by rob263
Expert Comment by rob263:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by mark_wills

Rank: Wizard

Expert Comment by mark_wills:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BenthamLtd
Author Comment by BenthamLtd:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BenthamLtd
Author Comment by BenthamLtd:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by mark_wills

Rank: Wizard

Accepted Solution by mark_wills:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by mark_wills

Rank: Wizard

Expert Comment by mark_wills:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628