‎12-16-2015 08:52 PM
Solved! Go to Solution.
‎12-17-2015 12:47 AM
Select Top 1000000 licenseview.LicenseidID,
licenseview.License,
licenseview.Nrlicenses,
licenseview.Priceperlicense,
licenseview.Missing,
licenseview.Price,
licenseview.[number in use],
usedsoftware.softwareName,
usedsoftware.SoftwarePublisher,
usedsoftware.softwareVersion,
usedsoftware.total As subtotal,
licenseview.LicenseTypeName,
licenseview.LicenseContact,
licenseview.LicenseOwner
From tblLicenses
Inner Join (Select Purchased.LicenseidID,
Purchased.softwareName As License,
Purchased.nrlicenses As Nrlicenses,
Purchased.Priceperlicense,
Purchased.LicenseTypeName,
Purchased.LicenseContact,
Purchased.LicenseOwner,
Sum(softwaretotal.Total) - Coalesce(Purchased.nrlicenses, 0) As Missing,
Case
When (Sum(softwaretotal.Total) > Coalesce(Purchased.nrlicenses,
0)) Then (Sum(softwaretotal.Total) - Coalesce(Purchased.nrlicenses, 0)) *
Purchased.Priceperlicense Else Null End As Price,
Sum(softwaretotal.Total) As [number in use]
From tblSublicenses
Inner Join (Select tblSoftwareUni.softwareName,
tblSoftware.softwareVersion,
tblSoftwareUni.SoftwarePublisher,
Count(tblSoftware.AssetID) As Total
From tblSoftware
Inner Join tblSoftwareUni On tblSoftware.softID = tblSoftwareUni.SoftID
Inner Join tblAssetCustom On tblSoftware.AssetID = tblAssetCustom.AssetID
Where tblAssetCustom.State = 1
Group By tblSoftwareUni.softwareName,
tblSoftware.softwareVersion,
tblSoftwareUni.SoftwarePublisher) softwaretotal
On softwaretotal.softwareName Like tblSublicenses.softwareName And
softwaretotal.softwareVersion Like tblSublicenses.softwareVersion
Right Outer Join (Select tblLicenses.softwareName,
tblLicenses.Priceperlicense,
tsyslicensetype.LicenseTypeName,
tblLicenses.LicenseContact,
tblLicenses.LicenseOwner,
Sum(tblSublicensesOrders.Nrlicenses) As nrlicenses,
tblLicenses.LicenseidID
From tblLicenses
Left Outer Join tsyslicensetype On tblLicenses.LicenseType =
tsyslicensetype.LicenseType
Left Outer Join tblSublicensesOrders On tblLicenses.LicenseidID =
tblSublicensesOrders.LicenseidID
Group By tblLicenses.softwareName,
tblLicenses.Priceperlicense,
tsyslicensetype.LicenseTypeName,
tblLicenses.LicenseContact,
tblLicenses.LicenseOwner,
tblLicenses.LicenseidID) Purchased On tblSublicenses.LicenseidID =
Purchased.LicenseidID
Group By Purchased.LicenseidID,
Purchased.softwareName,
Purchased.nrlicenses,
Purchased.Priceperlicense,
Purchased.LicenseTypeName,
Purchased.LicenseContact,
Purchased.LicenseOwner) licenseview On tblLicenses.LicenseidID =
licenseview.LicenseidID
Left Outer Join (tblSublicenses
Inner Join (Select tblSoftwareUni.softwareName,
tblSoftwareUni.SoftwarePublisher,
tblSoftware.softwareVersion,
Count(tblSoftware.AssetID) As total
From tblSoftware
Inner Join tblSoftwareUni On tblSoftware.softID = tblSoftwareUni.SoftID
Inner Join tblAssetCustom On tblSoftware.AssetID = tblAssetCustom.AssetID
Where tblAssetCustom.State = 1
Group By tblSoftwareUni.softwareName,
tblSoftwareUni.SoftwarePublisher,
tblSoftware.softwareVersion) usedsoftware On usedsoftware.softwareName Like
tblSublicenses.softwareName And usedsoftware.softwareVersion Like
tblSublicenses.softwareVersion) On tblLicenses.LicenseidID =
tblSublicenses.LicenseidID
Order By licenseview.License,
usedsoftware.softwareName,
usedsoftware.softwareVersion
‎12-17-2015 12:47 AM
Select Top 1000000 licenseview.LicenseidID,
licenseview.License,
licenseview.Nrlicenses,
licenseview.Priceperlicense,
licenseview.Missing,
licenseview.Price,
licenseview.[number in use],
usedsoftware.softwareName,
usedsoftware.SoftwarePublisher,
usedsoftware.softwareVersion,
usedsoftware.total As subtotal,
licenseview.LicenseTypeName,
licenseview.LicenseContact,
licenseview.LicenseOwner
From tblLicenses
Inner Join (Select Purchased.LicenseidID,
Purchased.softwareName As License,
Purchased.nrlicenses As Nrlicenses,
Purchased.Priceperlicense,
Purchased.LicenseTypeName,
Purchased.LicenseContact,
Purchased.LicenseOwner,
Sum(softwaretotal.Total) - Coalesce(Purchased.nrlicenses, 0) As Missing,
Case
When (Sum(softwaretotal.Total) > Coalesce(Purchased.nrlicenses,
0)) Then (Sum(softwaretotal.Total) - Coalesce(Purchased.nrlicenses, 0)) *
Purchased.Priceperlicense Else Null End As Price,
Sum(softwaretotal.Total) As [number in use]
From tblSublicenses
Inner Join (Select tblSoftwareUni.softwareName,
tblSoftware.softwareVersion,
tblSoftwareUni.SoftwarePublisher,
Count(tblSoftware.AssetID) As Total
From tblSoftware
Inner Join tblSoftwareUni On tblSoftware.softID = tblSoftwareUni.SoftID
Inner Join tblAssetCustom On tblSoftware.AssetID = tblAssetCustom.AssetID
Where tblAssetCustom.State = 1
Group By tblSoftwareUni.softwareName,
tblSoftware.softwareVersion,
tblSoftwareUni.SoftwarePublisher) softwaretotal
On softwaretotal.softwareName Like tblSublicenses.softwareName And
softwaretotal.softwareVersion Like tblSublicenses.softwareVersion
Right Outer Join (Select tblLicenses.softwareName,
tblLicenses.Priceperlicense,
tsyslicensetype.LicenseTypeName,
tblLicenses.LicenseContact,
tblLicenses.LicenseOwner,
Sum(tblSublicensesOrders.Nrlicenses) As nrlicenses,
tblLicenses.LicenseidID
From tblLicenses
Left Outer Join tsyslicensetype On tblLicenses.LicenseType =
tsyslicensetype.LicenseType
Left Outer Join tblSublicensesOrders On tblLicenses.LicenseidID =
tblSublicensesOrders.LicenseidID
Group By tblLicenses.softwareName,
tblLicenses.Priceperlicense,
tsyslicensetype.LicenseTypeName,
tblLicenses.LicenseContact,
tblLicenses.LicenseOwner,
tblLicenses.LicenseidID) Purchased On tblSublicenses.LicenseidID =
Purchased.LicenseidID
Group By Purchased.LicenseidID,
Purchased.softwareName,
Purchased.nrlicenses,
Purchased.Priceperlicense,
Purchased.LicenseTypeName,
Purchased.LicenseContact,
Purchased.LicenseOwner) licenseview On tblLicenses.LicenseidID =
licenseview.LicenseidID
Left Outer Join (tblSublicenses
Inner Join (Select tblSoftwareUni.softwareName,
tblSoftwareUni.SoftwarePublisher,
tblSoftware.softwareVersion,
Count(tblSoftware.AssetID) As total
From tblSoftware
Inner Join tblSoftwareUni On tblSoftware.softID = tblSoftwareUni.SoftID
Inner Join tblAssetCustom On tblSoftware.AssetID = tblAssetCustom.AssetID
Where tblAssetCustom.State = 1
Group By tblSoftwareUni.softwareName,
tblSoftwareUni.SoftwarePublisher,
tblSoftware.softwareVersion) usedsoftware On usedsoftware.softwareName Like
tblSublicenses.softwareName And usedsoftware.softwareVersion Like
tblSublicenses.softwareVersion) On tblLicenses.LicenseidID =
tblSublicenses.LicenseidID
Order By licenseview.License,
usedsoftware.softwareName,
usedsoftware.softwareVersion
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now