Sub WriteMfgModels() Dim dealerId : dealerId = Session("DealerID") If Len("" & dealerId) = 0 Then dealerId = "NULL" End If 'Dim sql : sql = "SELECT MFG.[ManufacturerID], MFG.[ManufacturerDescription], L.CleanModelNumber AS CleanedModelNumber, MAX(L.[ModelNumber]) AS ModelNumber, COUNT(L.[LiftID]) AS ListingCount " & _ ' "FROM [vLiftsActive] L " & _ ' "INNER JOIN dbo.fnGetVisibleListings(" & dealerId & ") VIS ON VIS.[LiftID] = L.[LiftID] " & _ ' "INNER JOIN [Manufacturer] MFG ON (L.[ManufacturerID] = MFG.[ManufacturerID] OR RTRIM(L.[ItemManufacturer]) = RTRIM(MFG.[ManufacturerDescription])) " & _ ' "INNER JOIN [Dealer] D ON L.[DealerID] = D.[DealerID] " & _ ' "WHERE L.[ModelNumber] IS NOT NULL AND " & _ ' "MFG.[ManufacturerID] <> 100 AND " & _ ' "RTRIM(MFG.[ManufacturerDescription]) <> 'used' AND " & _ ' "ISNULL(L.[HideOnElift], 0) <> 1 AND " & _ ' "ISNULL(L.[HideRetail], 0) <> 1 AND " & _ ' "D.[dealeractive] = 'yes' AND " & _ ' "D.[ShowOnElift] = 1 AND " & _ ' "(L.[ModelNumber] NOT LIKE '%!%' AND L.[ModelNumber] NOT LIKE '%Hours%' AND L.[ModelNumber] NOT LIKE '%$%') AND " & _ ' "L.[ExpireDate] > CONVERT(DATETIME, DATEDIFF(DAY, 0, GETDATE()) + 1) AND " & _ ' "LEN(RTRIM(D.[City])) > 0 " & _ ' "GROUP BY MFG.[ManufacturerID], MFG.[ManufacturerDescription], L.CleanModelNumber " & _ ' "ORDER BY MFG.[ManufacturerDescription], L.CleanModelNumber" Dim cte : cte = "WITH VisibleListings AS (SELECT L.[LiftID] FROM [vLiftsActive] L INNER JOIN [Dealer] D ON D.[DealerID] = L.[DealerID] " & _ "WHERE D.[dealeractive] = 'YES' AND D.[ShowOnElift] = 1 AND ISNULL(L.[HideOnElift], 0) <> 1 AND ISNULL(L.[HideRetail], 0) <> 1 " & _ "AND L.[ExpireDate] > CONVERT(DATETIME, DATEDIFF(DAY, 0, GETDATE()) + 1)) " Dim sql : sql = cte & "SELECT MFG.[ManufacturerID], MFG.[ManufacturerDescription], L.CleanModelNumber AS CleanedModelNumber, MAX(L.[ModelNumber]) AS ModelNumber, COUNT(L.[LiftID]) AS ListingCount " & _ "FROM [vLiftsActive] L " & _ "INNER JOIN VisibleListings VIS ON VIS.[LiftID] = L.[LiftID] " & _ "INNER JOIN [Manufacturer] MFG ON L.[ManufacturerID] = MFG.[ManufacturerID] " & _ "INNER JOIN [Dealer] D ON L.[DealerID] = D.[DealerID] " & _ "WHERE L.[ModelNumber] IS NOT NULL AND MFG.[ManufacturerID] <> 100 AND MFG.[ManufacturerDescription] <> 'used' AND LEN(RTRIM(D.[City])) > 0 " & _ "AND (L.[ModelNumber] NOT LIKE '%!%' AND L.[ModelNumber] NOT LIKE '%Hours%' AND L.[ModelNumber] NOT LIKE '%$%') " & _ "GROUP BY MFG.[ManufacturerID], MFG.[ManufacturerDescription], L.CleanModelNumber " & _ "ORDER BY MFG.[ManufacturerDescription], L.CleanModelNumber" Dim rs : Set rs = db.RetrieveRS(sql) Dim mfg_id : mfg_id = "0" Dim close_tags If Not (rs.BOF And rs.EOF) Then rs.MoveFirst mfg_id = rs("ManufacturerID") WriteMfgBoxStart rs While Not rs.EOF If CStr(mfg_id) <> CStr(rs("ManufacturerID")) Then WriteMfgBoxEnd WriteMfgBoxStart rs End If mfg_id = rs("ManufacturerID") Response.Write "

" & rs("ModelNumber") & " [" & rs("ListingCount") & "]

" rs.MoveNext Wend WriteMfgBoxEnd End If End Sub