ich bin ein stück weiter gekommen. HAbe eine Schleife erstellt. Aber jetzt macht er pro Tag eine eigene Abfrage, ich würde das aber in einer Tabelle haben und nicht in 30.…
declare @tag INT = 0
declare @max INT = 30
WHILE(@tag <= @max)
BEGIN
SELECT au.Name, a.Bezeichnung, ad.SerialNo, ad.InventNo, ad.PrinterIP,
(SELECT TOP (1) C1
FROM dbo.ACCMIBCOUNTERVALUES
WHERE (DeviceId = ad.Id) AND (CONVERT(date, TimeUTC) = CONVERT(date, GETDATE() -@tag))) AS Zähler0,
(SELECT TOP (1) sValue
FROM dbo.ACCSNMPHISTORY
WHERE (Name LIKE '%Toner%' OR
Name LIKE '%Kassette%') AND (SnmpColorant = 'black') AND (DeviceId = ad.Id) AND (CONVERT(date, TimeUTC) = CONVERT(date, GETDATE() -@tag))
ORDER BY TimeUTC DESC) AS schwarz0,
(SELECT TOP (1) sValue
FROM dbo.ACCSNMPHISTORY
WHERE (Name LIKE '%Toner%' OR
Name LIKE '%Kassette%') AND (SnmpColorant = 'cyan') AND (DeviceId = ad.Id) AND (CONVERT(date, TimeUTC) = CONVERT(date, GETDATE() -@tag))
ORDER BY TimeUTC DESC) AS cyan0,
(SELECT TOP (1) sValue
FROM dbo.ACCSNMPHISTORY
WHERE (Name LIKE '%Toner%' OR
Name LIKE '%Kassette%') AND (SnmpColorant = 'magenta') AND (DeviceId = ad.Id) AND (CONVERT(date, TimeUTC) = CONVERT(date, GETDATE() -@tag))
ORDER BY TimeUTC DESC) AS magenta0,
(SELECT TOP (1) sValue
FROM dbo.ACCSNMPHISTORY
WHERE (Name LIKE '%Toner%' OR
Name LIKE '%Kassette%') AND (SnmpColorant = 'yellow') AND (DeviceId = ad.Id) AND (CONVERT(date, TimeUTC) = CONVERT(date, GETDATE() -@tag))
ORDER BY TimeUTC DESC) AS gelb0
FROM dbo.ACCDEVICES AS ad INNER JOIN
dbo.ACCUSERS AS au ON au.Id = ad.SubmitterId INNER JOIN
scOffice61.dbo.Maschinen AS ma ON ma.MaschinenNummer COLLATE Latin1_General_CI_AS = ad.InventNo INNER JOIN
scOffice61.dbo.Artikel AS a ON a.ArtikelNummer COLLATE Latin1_General_CI_AS = ma.ArtikelNummer COLLATE Latin1_General_CI_AS
WHERE (ad.Obstacles = '0')
SET @tag = @tag +1
END