Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, November 22, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Data & Imports Forums - T-SQL & Queries
Forum to discuss general T-SQL questions and help with queries related to SalesLogix data. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to T-SQL & Queries | New ThreadView:  Search:  
 Author  Thread: Most recent history?
TheProf
Posts: 4
 
Most recent history?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 24 Oct 06 12:35 PM
fiogf49gjkf0d
Hello,

I hope everyone is doing well.

I would like to know how to create a query that will show me the last time a contact was touched, and show me what that item was - email, telephone call, note, etc.

I am able to get a query where it shows me ALL the history for a contact, but I would like it to show me only the most recent one. That way I can sort by that date, and know who is the oldest, and work forward by date in terms of contact, etc.

It would show something similar to the "SUMMARY" tab on the contact's view.

Please advise, as this has been a major problem for us for a long time.

Thank you
[Reply][Quote]
John Gundrum
Posts: 632
Top 10 forum poster: 632 posts
 
Re: Most recent history?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 25 Oct 06 6:42 AM
fiogf49gjkf0d
You have to create a SELECT statement that returns the historyid of the maximum create date for each contact history. The following SELECT statement will do this.
SELECT h.historyid FROM history h WHERE h.createdate = (SELECT MAX(z.createdate) FROM history z WHERE z.contactid = h.contactid)

You might want to add a time constraint to this because as your database grows, the longer it will take to execute the statement. When I ran it for all history it took SLX about 1 minute to pull back about 28,000 records. I added a time constraint of any history in the past 12 months as the next SELECT statement shows
SELECT h.historyid FROM history h WHERE h.createdate = (SELECT MAX(z.createdate) FROM history z WHERE z.contactid = h.contactid AND z.createdate >= DATEADD(mm, -12, GETDATE()))

To add this in a contact group add a condition for historyid, change the operator to IN and then paste one of the above SELECT statements in the 'Value is:' field and click OK.

John G.
[Reply][Quote]
TheProf
Posts: 4
 
Re: Most recent history?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 16 Nov 06 1:00 PM
fiogf49gjkf0d
Thank you!
[Reply][Quote]
Zeph
Posts: 37
 
Re: Most recent history?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Nov 06 9:43 AM
fiogf49gjkf0d
Just a small tweak on the query. I had used something similar but had trouble because there were multiple history records with the same createdate thus this would return more than 1 record for some contacts. Most of the time either way would work, because if you are just looking for the date you would get the same result either way. But I think this would restrict to 1 hist rec / contact.

SELECT h.historyid FROM history h WHERE h.historyid = (SELECT TOP 1 historyid FROM history z WHERE z.contactid = h.contactid ORDER BY createdate DESC)

Zeph
[Reply][Quote]
John Gundrum
Posts: 632
Top 10 forum poster: 632 posts
 
Re: Most recent history?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Nov 06 8:29 AM
fiogf49gjkf0d
True. The TOP n clause will work but only for a SQL Server backend. I don't think this will work for Oracle. Not sure if there is a SQL-99 equivalant of the TOP n clause.

John G.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 11/22/2024 9:50:25 AM