| Author |
Topic |
|
thehandsomecode
Yak Posting Veteran
51 Posts |
Posted - 2007-11-08 : 15:23:06
|
| when this query is run it returns the max value for each of the activity types eg. phone calls, emails etc.what i want to achieve is for it to return only one record. whichever is more recent. but it only has to be either a phone call or an email.SELECT regardingobjectidname, MAX(actualend) AS Last_Contacted_On, activitytypecodename, owneridnameFROM FilteredActivityPointer AS AWHERE (statecodename = 'completed') AND (activitytypecodename IN (@activitytypes))GROUP BY regardingobjectidname, activitytypecodename, owneridnameMelvin FelicienIT ManagerDCG Properties Limited |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-11-08 : 15:32:42
|
SELECT TOP 1 regardingobjectidname, actualend, activitytypecodename, owneridnameFROM FilteredActivityPointerWHERE statecodename = 'completed' AND activitytypecodename = @activitytypesorder by actualend desc E 12°55'05.25"N 56°04'39.16" |
 |
|
|
thehandsomecode
Yak Posting Veteran
51 Posts |
Posted - 2007-11-08 : 15:51:07
|
| This one doesnt work as it only returns 1 record but i need it to return one record for each "regardingobjectidname"Tableregardingobjectid | actualend | activitytype |Owneridnamemelvin felicien 10/10/07 email Matthewmelvin felicien 12/10/07 phone matthewi need it to only return record number two because its the most recent. but this has to be run against a databas with thousands of regardingobjectid'sPlease helpCompnetsyslc |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-11-08 : 15:56:37
|
Are you using SQL Server 2005 or SQL Server 2000? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
thehandsomecode
Yak Posting Veteran
51 Posts |
Posted - 2007-11-08 : 15:59:39
|
| 2005Compnetsyslc |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-11-08 : 16:01:28
|
[code]SELECT regardingobjectid, actualend, activitytype, Owneridnamefrom ( SELECT regardingobjectid, actualend, activitytype, Owneridname, row_number() Over (Partition by regardingobjectid order by actualend desc) as recid FROM FilteredActivityPointer WHERE statecodename = 'completed' AND activitytypecodename = @activitytypes ) as dwhere recid = 1[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-11-08 : 17:23:56
|
Well? Did it work? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
thehandsomecode
Yak Posting Veteran
51 Posts |
Posted - 2007-11-08 : 17:42:30
|
| Yes thank you. you are a star. it did work. Compnetsyslc |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-11-08 : 17:46:19
|
Good.It's good netiquette to provide feedback to those helping you for free of charge. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|