Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
neb2886
Starting Member
4 Posts |
Posted - 2012-03-08 : 10:23:37
|
| Hi, first time poster here.I need this query to pull just the last scan date, i.e. if a scan ran on 3/7/2012 I need just the records (there may be few or many) that pertain to that date and no other dates. When I run this query I am still getting all of the results (i.e. scan dates of 3/7/2012, 3/5/2012, 3/1/2012, etc)Can you see something wrong that would be causing this? I just need the most recent date, even if there are many records for that date (i.e. 10 IP addresses that were all scanned on 3/5/2012)SELECT CPA.ScanName,CPA.pspplMSSeverity,CPA.smachIPAddress,SDA.PatchMissing,MAX(CPA.ScanDate)FROM qryReportsCondensedPatchesAggregate CPAINNER JOIN qryReportsScanSummaryWithDetailsAggregate SDAON CPA.smachIPAddress=SDA.smachIPAddressWHERE CPA.ScanName LIKE '%mgmt%'GROUP BY CPA.ScanName, CPA.pspplMSSeverity, CPA.smachIPAddress, SDA.PatchMissing, CPA.ScanDateORDER BY CPA.ScanDate DESC |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-08 : 10:28:35
|
| can you show some sample data and then explain what you want?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
neb2886
Starting Member
4 Posts |
Posted - 2012-03-08 : 10:41:26
|
| Column1 smachIPAddress ScanName pspplMSSeverity PatchMissing3/5/2012 15:24 162.1.1.1 Mgmt Servers OU 0 13/5/2012 15:24 162.1.1.1 Mgmt Servers OU 0 13/5/2012 15:24 1162.1.1.1 Mgmt Servers OU 0 13/5/2012 15:24 162.1.1.1 Mgmt Servers OU 0 23/5/2012 15:24 162.1.1.1 Mgmt Servers OU 0 13/1/2012 17:29 162.1.1.1 Mgmt Servers OU 0 23/1/2012 17:29 162.1.1.1 Mgmt Servers OU 0 43/1/2012 17:29 162.1.1.1 Mgmt Servers OU 0 23/1/2012 17:29 162.1.1.1 Mgmt Servers OU 0 33/1/2012 17:29 162.1.1.1 Mgmt Servers OU 0 13/1/2012 17:29 162.1.1.1 Mgmt Servers OU 0 3I would like the query to run and only show the most records for the most recent scan date (in this case 3/5/2012, 5 records). Right now the query is pulling all of the dates. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-08 : 10:44:26
|
| [code]SELECT ScanName,pspplMSSeverity,smachIPAddress,PatchMissing,ScanDateFROM(SELECT CPA.ScanName,CPA.pspplMSSeverity,CPA.smachIPAddress,SDA.PatchMissing,CPA.ScanDate,DENSE_RANK() OVER (ORDER BY CPA.ScanDate DESC) AS RnkFROM qryReportsCondensedPatchesAggregate CPAINNER JOIN qryReportsScanSummaryWithDetailsAggregate SDAON CPA.smachIPAddress=SDA.smachIPAddressWHERE CPA.ScanName LIKE '%mgmt%')tWHERE rnk=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
neb2886
Starting Member
4 Posts |
Posted - 2012-03-08 : 11:03:40
|
| Thank you, this worked perfectly. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-08 : 11:37:47
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|