[size=9]
When I take out the where clause it will not run anymore I get an error when I am trying to update it.[/size]
Select Top 1000000 tblLicenses.softwareName As [Software Name],
tblLicenses.Priceperlicense As [Unit Price],
InUseCount.InUseLicenses As [In Use],
LicenseCount.PurchasedLicenses As Purchased,
(InUseCount.InUseLicenses - LicenseCount.PurchasedLicenses) As Shortfall,
Case When (InUseCount.InUseLicenses - (Case
When LicenseCount.PurchasedLicenses Is Null Then 0
Else LicenseCount.PurchasedLicenses
End)) > 0 Then (InUseCount.InUseLicenses - (Case
When LicenseCount.PurchasedLicenses Is Null Then 0
Else LicenseCount.PurchasedLicenses End)) * tblLicenses.Priceperlicense
Else Null End As Cost,
tblSublicensesOrders.Orderdate,
tblSublicensesOrders.Nrlicenses,
tblSublicensesOrders.Priceperlicense,
tblSublicensesOrders.Ordernumber,
tblSublicensesOrders.Comments,
tblSublicensesOrders.Licensekey
From tblLicenses
Left Join (Select tblSublicensesOrders.LicenseidID,
Sum(tblSublicensesOrders.Nrlicenses) As PurchasedLicenses
From tblSublicensesOrders
Group By tblSublicensesOrders.LicenseidID) As LicenseCount
On LicenseCount.LicenseidID = tblLicenses.LicenseidID
Left Join (Select tblSublicenses.LicenseidID,
Count(*) As InUseLicenses
From tblSublicenses
Inner Join (Select tblSoftwareUni.softwareName,
tblSoftware.softwareVersion
From tblSoftware
Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblSoftware.softID
Inner Join tblAssetCustom On tblAssetCustom.AssetID = tblSoftware.AssetID
Where tblAssetCustom.State = 1) As Software On Software.softwareName =
tblSublicenses.softwareName And Software.softwareVersion =
tblSublicenses.softwareVersion
Group By tblSublicenses.LicenseidID) As InUseCount On InUseCount.LicenseidID =
tblLicenses.LicenseidID
Left Join tblSublicensesOrders On tblLicenses.LicenseidID =
tblSublicensesOrders.LicenseidID
Order By [Software Name]
[size=9]
This is the one that give me the error. [/size]
Select Top 1000000 tblLicenses.softwareName As [Software Name],
tblLicenses.Priceperlicense As [Unit Price],
InUseCount.InUseLicenses As [In Use],
LicenseCount.PurchasedLicenses As Purchased,
(InUseCount.InUseLicenses - LicenseCount.PurchasedLicenses) As Shortfall,
Case When (InUseCount.InUseLicenses - (Case
When LicenseCount.PurchasedLicenses Is Null Then 0
Else LicenseCount.PurchasedLicenses
End)) > 0 Then (InUseCount.InUseLicenses - (Case
When LicenseCount.PurchasedLicenses Is Null Then 0
Else LicenseCount.PurchasedLicenses End)) * tblLicenses.Priceperlicense
Else Null End As Cost,
tblSublicensesOrders.Orderdate,
tblSublicensesOrders.Nrlicenses,
tblSublicensesOrders.Priceperlicense,
tblSublicensesOrders.Ordernumber,
tblSublicensesOrders.Comments,
tblSublicensesOrders.Licensekey
From tblLicenses
Left Join (Select tblSublicensesOrders.LicenseidID,
Sum(tblSublicensesOrders.Nrlicenses) As PurchasedLicenses
From tblSublicensesOrders
Group By tblSublicensesOrders.LicenseidID) As LicenseCount
On LicenseCount.LicenseidID = tblLicenses.LicenseidID
Left Join (Select tblSublicenses.LicenseidID,
Count(*) As InUseLicenses
From tblSublicenses
Inner Join (Select tblSoftwareUni.softwareName,
tblSoftware.softwareVersion
From tblSoftware
Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblSoftware.softID
Inner Join tblAssetCustom On tblAssetCustom.AssetID = tblSoftware.AssetID) As Software On Software.softwareName =
tblSublicenses.softwareName And Software.softwareVersion =
tblSublicenses.softwareVersion
Group By tblSublicenses.LicenseidID) As InUseCount On InUseCount.LicenseidID =
tblLicenses.LicenseidID
Left Join tblSublicensesOrders On tblLicenses.LicenseidID =
tblSublicensesOrders.LicenseidID
Order By [Software Name]