Hi all,
Can this query be any shorter or better, please help
Thanks!
Can this query be any shorter or better, please help
Code:
sql = "SELECT " _
& " (SELECT SUM(moneySaleTotal) FROM tblCPBPS " _
& " WHERE idCPBPScat = 1 " _
& " AND idUser <> 4 " _
& " AND dtAddDate LIKE '" & gMonth & "%" & gYear & "%' " _
& " AND custType = 'Reseller') AS tMonthlySumReseller, " _
& " (SELECT SUM(moneySaleTotal) FROM tblCPBPS " _
& " WHERE idCPBPScat = 1 " _
& " AND idUser <> 4 " _
& " AND dtAddDate LIKE '%" & gYear & "%' " _
& " AND custType = 'Reseller') AS tYearlySumReseller, " _
& " (SELECT SUM(moneySaleTotal) FROM tblCPBPS " _
& " WHERE idCPBPScat = 1 " _
& " AND idUser <> 4 " _
& " AND dtAddDate LIKE '" & gMonth & "%" & gYear & "%' " _
& " AND custType = 'Manufacturer') AS tMonthlySumManu, " _
& " (SELECT SUM(moneySaleTotal) FROM tblCPBPS " _
& " WHERE idCPBPScat = 1 " _
& " AND idUser <> 4 " _
& " AND dtAddDate LIKE '%" & gYear & "%' " _
& " AND custType = 'Manufacturer') AS tYearlySumManu, " _
& " (SELECT SUM(moneySaleTotal) FROM tblCPBPS " _
& " WHERE idCPBPScat = 1 " _
& " AND idUser <> 4 " _
& " AND dtAddDate LIKE '" & gMonth & "%" & gYear & "%' " _
& " AND custType = 'Government') AS tMonthlySumGovt, " _
& " (SELECT SUM(moneySaleTotal) FROM tblCPBPS " _
& " WHERE idCPBPScat = 1 " _
& " AND idUser <> 4 " _
& " AND dtAddDate LIKE '%" & gYear & "%' " _
& " AND custType = 'Government') AS tYearlySumGovt, " _
& " (SELECT SUM(moneySaleTotal) FROM tblCPBPS " _
& " WHERE idCPBPScat = 1 " _
& " AND idUser <> 4 " _
& " AND dtAddDate LIKE '" & gMonth & "%" & gYear & "%' " _
& " AND custType = 'Other') AS tMonthlySumOther, " _
& " (SELECT SUM(moneySaleTotal) FROM tblCPBPS " _
& " WHERE idCPBPScat = 1 " _
& " AND idUser <> 4 " _
& " AND dtAddDate LIKE '%" & gYear & "%' " _
& " AND custType = 'Other') AS tYearlySumOther, " _
& " (SELECT SUM(numQty) FROM tblCPBPS " _
& " WHERE idCPBPScat = 2 " _
& " AND idUser <> 4) AS tSumKitQuotes, " _
& " (SELECT SUM(numQty) FROM tblCPBPS " _
& " WHERE idCPBPScat = 1 " _
& " AND idUser <> 4) AS tSumKitSold, " _
& " (SELECT COUNT(*) FROM tblCPBPS " _
& " WHERE idProdCat = 3 " _
& " AND idUser <> 4) AS tSumKitDemo, " _
& " (SELECT COUNT(*) FROM tblCPBPS " _
& " WHERE bolChkNew = '1' " _
& " AND idUser <> 4) AS tSumNewResellers " _
& "FROM tblCPBPS"