‎12-11-2014 01:25 AM
.
Select Top 1000000 tblAssets.AssetName,
tblAssets.AssetName,
tblAssets.Domain,
tblMonitor.MonitorModel As [Monitor 1 Model],
tblMonitor.MonitorManufacturer As [Monitor 1 Vendor],
tblMonitor.SerialNumber As [Monitor 1 Serial],
tblMonitor1.MonitorModel As [Monitor 2 Model],
tblMonitor1.MonitorManufacturer As [Monitor 2 Vendor],
tblMonitor1.SerialNumber As [Monitor 2 Serial],
TsysLastscan.Lasttime As [Monitor Last Scanned]
From tblAssets
Left Join (Select tblAssets.AssetName,
Min(tblMonitor.MonitorID) As Monitor1ID
From tblMonitor
Group By tblAssets.AssetName) Monitor1 On Monitor1.Computername =
tblAssets.AssetName
Left Join tblMonitor On tblMonitor.Computername = Monitor1.Computername And
tblMonitor.MonitorID = Monitor1.Monitor1ID
Inner Join TsysLastscan On tblAssets.AssetName = TsysLastscan.Computername
Inner Join TsysWaittime On TsysWaittime.CFGCode = TsysLastscan.CFGcode
Left Join (Select tblMonitor.Computername,
Count(tblMonitor.MonitorID) As [Monitor Count]
From tblMonitor
Group By tblMonitor.Computername
Having Count(tblMonitor.MonitorID) = 2) MonitorCount
On MonitorCount.Computername = tblAssets.AssetName
Left Join (Select tblMonitor.Computername,
Max(tblMonitor.MonitorID) As Monitor2ID
From tblMonitor
Group By tblMonitor.Computername) Monitor2 On Monitor2.Computername =
MonitorCount.Computername
Left Join tblMonitor tblMonitor1 On tblMonitor1.Computername =
Monitor2.Computername And tblMonitor1.MonitorID = Monitor2.Monitor2ID
Where tblAssets.Lastseen <> '' And TsysWaittime.CFGname = 'monitor'
Order By tblAssets.Domain,
tblAssets.AssetName
Solved! Go to Solution.
‎12-16-2014 09:24 PM
RC62N wrote:
ChangingCast(t2.ManufacturedDate As varchar(10))to VarChar(11 ) appears to fix that.
Select Distinct Top 1000000 tblAssets.AssetID,
tblAssets.AssetName,
tsysAssetTypes.AssetTypename,
tsysAssetTypes.AssetTypeIcon10 As icon,
tblAssets.IPAddress,
tblAssets.Lastseen,
tblAssets.Lasttried,
Stuff((Select ', ' + Cast(t2.MonitorModel As varchar(10)) From tblMonitor t2
Where t1.AssetID = t2.AssetID For Xml Path('')), 1, 2, '') Monitors,
countMonitor.numberMonitors As [Number monitors],
Stuff((Select ', ' + Cast(t2.SerialNumber As varchar(10)) From tblMonitor t2
Where t1.AssetID = t2.AssetID For Xml Path('')), 1, 2, '') SerialNumbers,
Stuff((Select ', ' + Cast(t2.MonitorManufacturer As varchar(10))
From tblMonitor t2
Where t1.AssetID = t2.AssetID For Xml Path('')), 1, 2,
'') MonitorManufacturer,
Stuff((Select ', ' + Cast(t2.ManufacturedDate As varchar(20))
From tblMonitor t2
Where t1.AssetID = t2.AssetID For Xml Path('')), 1, 2, '') ManufacturedDate,
tblAssets.Username,
tsysIPLocations.IPLocation
From tblAssets
Inner Join tsysIPLocations
On tblAssets.IPNumeric Between tsysIPLocations.StartIP And
tsysIPLocations.EndIP
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
Inner Join tblMonitor t1 On tblAssets.AssetID = t1.AssetID
Inner Join (Select tblMonitor.AssetID,
Count(tblMonitor.MonitorID) As numberMonitors
From tblMonitor
Group By tblMonitor.AssetID) countMonitor On countMonitor.AssetID =
tblAssets.AssetID
Where countMonitor.numberMonitors > 1 And tblAssetCustom.State = 1
Order By tblAssets.AssetName
‎11-15-2018 09:59 PM
Select Top 10000 tblAssets.AssetID,
tblAssets.AssetName,
tblAssets.Domain,
tsysAssetTypes.AssetTypename,
tsysOS.OSname,
tsysAssetTypes.AssetTypeIcon10 As icon,
tblAssets.IPAddress,
countMonitor.numberMonitors As [Number monitors],
CaseWhen tblMonitor.MonitorManufacturer = 'ACR' Then 'Acer'
When tblMonitor.MonitorManufacturer = 'ACI' Then 'Asus'
When tblMonitor.MonitorManufacturer = 'BNQ' Then 'BenQ'
When tblMonitor.MonitorManufacturer = 'HWP' Then 'HP'
When tblMonitor.MonitorManufacturer = 'LEN' Then 'Lenovo'
When tblMonitor.MonitorManufacturer = 'LGD' Then 'LG'
When tblMonitor.MonitorManufacturer = 'LPL' Then 'LG'
When tblMonitor.MonitorManufacturer = 'GSM' Then 'LG'
When tblMonitor.MonitorManufacturer = 'PHL' Then 'Philips'
When tblMonitor.MonitorManufacturer = 'SEC' Then 'Samsung'
When tblMonitor.MonitorManufacturer = 'IVM' Then 'Iiyama'
When tblMonitor.MonitorManufacturer = 'MAX' Then 'Maxdata'
When tblMonitor.MonitorManufacturer = 'SNY' Then 'Sony'
When tblMonitor.MonitorManufacturer = 'SYN' Then 'Samsung'
When tblMonitor.MonitorManufacturer = 'ENC' Then 'EIZO'
When tblMonitor.MonitorManufacturer = 'NEC' Then 'NEC Technologies'
When tblMonitor.MonitorManufacturer = 'FUS' Then 'Fujitsu Siemens'
When tblMonitor.MonitorManufacturer Like '%FUJ%' Then 'Fujitsu Siemens'
When tblMonitor.MonitorManufacturer Like '%DEL%' Then 'Dell'
When tblMonitor.MonitorManufacturer Like '%SAM%' Then 'Samsung'
When tblMonitor.MonitorManufacturer Like '%Lenovo%' Then 'Lenovo'
When tblMonitor.MonitorManufacturer Like 'AUO' Then 'AU Optronics'
When tblMonitor.MonitorManufacturer Like 'BenQ' Then 'BenQ'
Else ''
End As [Monitor Manufacturer 1],
tblMonitor.MonitorModel As [S/N 1],
CaseWhen tblMonitor.MonitorModel Like '%19%' Then '19"'
When tblMonitor.MonitorModel Like '%22%' Then '22"'
When tblMonitor.MonitorModel Like '%23%' Then '23"'
When tblMonitor.MonitorModel Like '%24%' Then '24"'
When tblMonitor.MonitorModel Like '%27%' Then '27"'
When tblMonitor.MonitorModel Like '%201%' Then '20"'
When tblMonitor.MonitorModel Like '%Sony TV%' Then '50"'
When tblMonitor.MonitorModel Like '%L768%' Then '19"'
Else ''
End As [Size 1],
tblMonitor.SerialNumber As [Serial Number 1],
Case
When tblMonitor1.MonitorManufacturer = 'ACR' Then 'Acer'
When tblMonitor1.MonitorManufacturer = 'ACI' Then 'Asus'
When tblMonitor1.MonitorManufacturer = 'BNQ' Then 'BenQ'
When tblMonitor1.MonitorManufacturer = 'HWP' Then 'HP'
When tblMonitor1.MonitorManufacturer = 'LEN' Then 'Lenovo'
When tblMonitor1.MonitorManufacturer = 'LGD' Then 'LG'
When tblMonitor1.MonitorManufacturer = 'LPL' Then 'LG'
When tblMonitor1.MonitorManufacturer = 'GSM' Then 'LG'
When tblMonitor1.MonitorManufacturer = 'PHL' Then 'Philips'
When tblMonitor1.MonitorManufacturer = 'SEC' Then 'Samsung'
When tblMonitor1.MonitorManufacturer = 'IVM' Then 'Iiyama'
When tblMonitor1.MonitorManufacturer = 'MAX' Then 'Maxdata'
When tblMonitor1.MonitorManufacturer = 'SNY' Then 'Sony'
When tblMonitor1.MonitorManufacturer = 'SYN' Then 'Samsung'
When tblMonitor1.MonitorManufacturer = 'ENC' Then 'EIZO'
When tblMonitor1.MonitorManufacturer = 'NEC' Then 'NEC Technologies'
When tblMonitor1.MonitorManufacturer = 'FUS' Then 'Fujitsu Siemens'
When tblMonitor1.MonitorManufacturer Like '%FUJ%' Then 'Fujitsu Siemens'
When tblMonitor1.MonitorManufacturer Like '%DEL%' Then 'Dell'
When tblMonitor1.MonitorManufacturer Like '%SAM%' Then 'Samsung'
When tblMonitor1.MonitorManufacturer Like '%Lenovo%' Then 'Lenovo'
When tblMonitor1.MonitorManufacturer Like 'AUO' Then 'AU Optronics'
When tblMonitor1.MonitorManufacturer Like 'BenQ' Then 'BenQ'
Else ''
End As [Monitor Manufacturer 2],
tblMonitor1.MonitorModel As [S/N 2],
CaseWhen tblMonitor1.MonitorModel Like '%19%' Then '19"'
When tblMonitor1.MonitorModel Like '%22%' Then '22"'
When tblMonitor1.MonitorModel Like '%23%' Then '23"'
When tblMonitor1.MonitorModel Like '%24%' Then '24"'
When tblMonitor1.MonitorModel Like '%27%' Then '27"'
When tblMonitor1.MonitorModel Like '%201%' Then '20"'
When tblMonitor1.MonitorModel Like '%Sony TV%' Then '50"'
When tblMonitor1.MonitorModel Like '%L768%' Then '19"'
Else ''
End As [Size 2],
tblMonitor1.SerialNumber As [Serial Number 2]
From tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
Inner Join tsysOS On tblAssets.OScode = tsysOS.OScodeLeft Join (Select tblMonitor.AssetID,
Count(tblMonitor.MonitorID) As numberMonitors
From tblMonitor
Where tblMonitor.MonitorModel Not Like '%LCD 1366%' And
tblMonitor.MonitorModel Not Like '%Non-PnP%' And
tblMonitor.MonitorModel Not Like '%LCD 1600x900%' And
tblMonitor.MonitorModel Not Like '%LTN125AT01401%' And
tblMonitor.MonitorModel Not Like '%B125XW01 V0%' And
tblMonitor.MonitorManufacturer Not Like '%AUO%' And
tblMonitor.MonitorManufacturer Not Like '%LGD%'
Group By tblMonitor.AssetID) countMonitor On countMonitor.AssetID =
tblAssets.AssetIDLeft Join (Select Top 10000 tblMonitor.AssetID,
Min(tblMonitor.MonitorID) As Monitor1ID
From tblMonitor
Where tblMonitor.MonitorModel Not Like '%LCD 1366%' And
tblMonitor.MonitorModel Not Like '%Non-PnP%' And
tblMonitor.MonitorModel Not Like '%LCD 1600x900%' And
tblMonitor.MonitorModel Not Like '%LTN125AT01401%' And
tblMonitor.MonitorModel Not Like '%B125XW01 V0%' And
tblMonitor.MonitorManufacturer Not Like '%AUO%' And
tblMonitor.MonitorManufacturer Not Like '%LGD%'
Group By tblMonitor.AssetID) As Monitor1 On tblAssets.AssetID =
Monitor1.AssetID
Left Join tblMonitor On Monitor1.Monitor1ID = tblMonitor.MonitorIDLeft Join (Select Top 10000 tblMonitor.AssetID,
Max(tblMonitor.MonitorID) As Monitor2ID
From tblMonitor
Where tblMonitor.MonitorModel Not Like '%LCD 1366%' And
tblMonitor.MonitorModel Not Like '%Non-PnP%' And
tblMonitor.MonitorModel Not Like '%LCD 1600x900%' And
tblMonitor.MonitorModel Not Like '%LTN125AT01401%' And
tblMonitor.MonitorModel Not Like '%B125XW01 V0%' And
tblMonitor.MonitorManufacturer Not Like '%AUO%' And
tblMonitor.MonitorManufacturer Not Like '%LGD%'
Group By tblMonitor.AssetID) As Monitor2 On tblAssets.AssetID =
Monitor2.AssetID
Left Join tblMonitor tblMonitor1 On Monitor2.Monitor2ID =
tblMonitor1.MonitorID And Monitor2.Monitor2ID != Monitor1.Monitor1IDLeft Join (Select tblMonitor.AssetID,
Count(tblMonitor.MonitorID) As [Monitor Count]
From tblMonitor
Where tblMonitor.MonitorModel Not Like '%LCD 1366%' And
tblMonitor.MonitorModel Not Like '%Non-PnP%' And
tblMonitor.MonitorModel Not Like '%LCD 1600x900%' And
tblMonitor.MonitorModel Not Like '%LTN125AT01401%' And
tblMonitor.MonitorModel Not Like '%B125XW01 V0%' And
tblMonitor.MonitorManufacturer Not Like '%AUO%' And
tblMonitor.MonitorManufacturer Not Like '%LGD%'
Group By tblMonitor.AssetID
Having Count(tblMonitor.MonitorID) = 2) As MonitorCount On
tblAssets.AssetID = MonitorCount.AssetID
Order By tblAssets.AssetName
‎10-18-2017 04:10 PM
‎10-17-2017 12:24 PM
Invalid SELECT statement. Unexpected token " Where" at line 9, pos 1.: Unexpected token " Where" at line 9, column 1
Website Version: 6.0.100.75
SERVERNAME: 6.0.100.75
SERVERNAME\SQLEXPRESS
Microsoft SQL Server 2014 - 12.0.2000.8 (X64) Feb 20 2014 20:04:26 Copyright (c) Microsoft Corporation Express Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
‎01-23-2015 08:52 AM
‎01-22-2015 07:54 PM
Error while saving report: "There was an error parsing the query. [ Token line number = 1,Token line offset = 208,Token in error = Select]"
‎12-16-2014 05:43 PM
Cast(t2.ManufacturedDate As varchar(10))to VarChar(
‎12-16-2014 09:24 PM
RC62N wrote:
ChangingCast(t2.ManufacturedDate As varchar(10))to VarChar(11 ) appears to fix that.
Select Distinct Top 1000000 tblAssets.AssetID,
tblAssets.AssetName,
tsysAssetTypes.AssetTypename,
tsysAssetTypes.AssetTypeIcon10 As icon,
tblAssets.IPAddress,
tblAssets.Lastseen,
tblAssets.Lasttried,
Stuff((Select ', ' + Cast(t2.MonitorModel As varchar(10)) From tblMonitor t2
Where t1.AssetID = t2.AssetID For Xml Path('')), 1, 2, '') Monitors,
countMonitor.numberMonitors As [Number monitors],
Stuff((Select ', ' + Cast(t2.SerialNumber As varchar(10)) From tblMonitor t2
Where t1.AssetID = t2.AssetID For Xml Path('')), 1, 2, '') SerialNumbers,
Stuff((Select ', ' + Cast(t2.MonitorManufacturer As varchar(10))
From tblMonitor t2
Where t1.AssetID = t2.AssetID For Xml Path('')), 1, 2,
'') MonitorManufacturer,
Stuff((Select ', ' + Cast(t2.ManufacturedDate As varchar(20))
From tblMonitor t2
Where t1.AssetID = t2.AssetID For Xml Path('')), 1, 2, '') ManufacturedDate,
tblAssets.Username,
tsysIPLocations.IPLocation
From tblAssets
Inner Join tsysIPLocations
On tblAssets.IPNumeric Between tsysIPLocations.StartIP And
tsysIPLocations.EndIP
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
Inner Join tblMonitor t1 On tblAssets.AssetID = t1.AssetID
Inner Join (Select tblMonitor.AssetID,
Count(tblMonitor.MonitorID) As numberMonitors
From tblMonitor
Group By tblMonitor.AssetID) countMonitor On countMonitor.AssetID =
tblAssets.AssetID
Where countMonitor.numberMonitors > 1 And tblAssetCustom.State = 1
Order By tblAssets.AssetName
‎12-16-2014 08:20 AM
‎12-15-2014 11:27 AM
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now