I've been looking through the forum's, and have come up with a few SQL queries to identify duplates and to delete them, however it doesn't appear to have any affect on the license counts in use as per the GUI on the home screen of the SEPM.
We are running 12.1 RU6MP1a.
Also in querieng the SEM_COMPTTER, SEM_CLIENT and SEM_AGENT tables as well as doing inner joins og each table on the COmputer_ID field, the SQL query results all vary with different ammounts, and the SEPM Licensing window (showing t he number of licenses in use) shows a different number as well, none of the number match up.
Here are my sample queries, I also have them for the SEM_Client table as well.
Please advise how I can write the correct query to find and delete all duplicates so that my in use license count decreases, as currently the only way to do this is to delete them manyaually form the SEPM and with over 600 machines a day to remove it is not feasible to do manually. Changing the SEPM system setting to auto-purge machines older than X days can;t be adjusted below the set 30 day limit for auditing purposes.
Find all machines in the table:
DECLARE @TimeZoneDiff int
SELECT @TimeZoneDiff = datediff(minute, getutcdate(), getdate())
SELECT computer_ID
, computer_name
, TIME_STAMP
, dateadd(minute, @TimeZoneDiff, dateadd(second, TIME_STAMP/1000, '01-01-1970 00:00:00')) as [TimeStamp]
, dateadd(s,convert(bigint,TIME_STAMP)/1000,'01-01-1970 00:00:00') LastUpdateTime
, DATEDIFF(dd,(dateadd(s,convert(bigint,TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) as [TCddDate Diff]
, DATEDIFF(hh,(dateadd(s,convert(bigint,TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) as [TChhDate Diff]
, DATEDIFF(mm,(dateadd(s,convert(bigint,TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) as [TCmmDate Diff]
FROM SEM_COMPUTER
GROUP BY computer_name, TIME_STAMP, computer_ID
Order by computer_name, TIME_STAMP
Find Duplicates in the table:
DECLARE @TimeZoneDiff int
SELECT @TimeZoneDiff = datediff(minute, getutcdate(), getdate())
SELECT Table1.computer_ID
, Table1.COMPUTER_NAME
, Table2.computer_name
, COUNT(Table2.COMPUTER_NAME) AS NumOccurrences
, Table1.TIME_STAMP
, dateadd(minute, @TimeZoneDiff, dateadd(second, Table1.TIME_STAMP/1000, '01-01-1970 00:00:00')) as [TimeStamp]
, dateadd(s,convert(bigint,Table1.TIME_STAMP)/1000,'01-01-1970 00:00:00') LastUpdateTime
, DATEDIFF(dd,(dateadd(s,convert(bigint,Table1.TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) as [TCddDate Diff]
, DATEDIFF(hh,(dateadd(s,convert(bigint,Table1.TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) as [TChhDate Diff]
, DATEDIFF(mm,(dateadd(s,convert(bigint,Table1.TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) as [TCmmDate Diff]
, COUNT(Table1.COMPUTER_NAME) AS [NumOccurrences]
, row_number() OVER(PARTITION BY Table1.COMPUTER_NAME ORDER BY Table1.TIME_STAMP) AS [rn]
FROM SEM_COMPUTER As Table1
inner join SEM_COMPUTER as Table2 on Table1.COMPUTER_NAME = Table2.COMPUTER_NAME
Where DATEDIFF(dd,(dateadd(s,convert(bigint,Table1.TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) > 2
and table2.COMPUTER_NAME != 'CTXTEMPLATE'
and table2.COMPUTER_NAME != 'DALW2K8R2UPDT'
and table2.COMPUTER_NAME != 'W2K8R2CTXUPDT'
GROUP BY table2.computer_name, Table1.computer_name, Table1.COMPUTER_ID, table1.TIME_STAMP
HAVING (count(table2.computer_name)>1)
Order by Table1.COMPUTER_NAME, Table1.TIME_STAMP
Delete duplicates form the table:
DECLARE @TimeZoneDiff int
SELECT @TimeZoneDiff = datediff(minute, getutcdate(), getdate())
SELECT Table1.computer_ID
, Table1.COMPUTER_NAME
-- , Table2.computer_name
, COUNT(Table2.COMPUTER_NAME) AS NumOccurrences
, Table1.TIME_STAMP
, dateadd(minute, @TimeZoneDiff, dateadd(second, Table1.TIME_STAMP/1000, '01-01-1970 00:00:00')) as [TimeStamp]
, dateadd(s,convert(bigint,Table1.TIME_STAMP)/1000,'01-01-1970 00:00:00') LastUpdateTime
, DATEDIFF(dd,(dateadd(s,convert(bigint,Table1.TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) as [TCddDate Diff]
, DATEDIFF(hh,(dateadd(s,convert(bigint,Table1.TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) as [TChhDate Diff]
, DATEDIFF(mm,(dateadd(s,convert(bigint,Table1.TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) as [TCmmDate Diff]
-- , COUNT(Table1.COMPUTER_NAME) AS [NumOccurrences]
, row_number() OVER(PARTITION BY Table1.COMPUTER_NAME ORDER BY Table1.TIME_STAMP) AS [rn]
into #temp FROM SEM_COMPUTER As Table1
inner join SEM_COMPUTER as Table2 on Table1.COMPUTER_NAME = Table2.COMPUTER_NAME
Where DATEDIFF(dd,(dateadd(s,convert(bigint,Table1.TIME_STAMP)/1000,'01-01-1970 00:00:00')),GETDATE()) > 2
and table2.COMPUTER_NAME != 'CTXTEMPLATE'
and table2.COMPUTER_NAME != 'DALW2K8R2UPDT'
and table2.COMPUTER_NAME != 'W2K8R2CTXUPDT'
GROUP BY table2.computer_name, Table1.computer_name, Table1.COMPUTER_ID, table1.TIME_STAMP
HAVING (count(table2.computer_name)>1)
--Order by Table1.COMPUTER_NAME, Table1.TIME_STAMP
delete from SEM_COMPUTER where COMPUTER_ID in(select COMPUTER_ID from #temp)
drop table #temp