I got an unable to parse query
Main Topics
Browse All TopicsI need to also show in this groupby view the percentage of vehicles checked dbo.vehicles.checked
This is a bit feild for either checked or not 1 or 0 1 begin checked.
How would I accomplish this?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
In correct syntax near keyword with
WITH A(username, id, ....., checked, ...dealerid2) AS (SELECT dbo.auditors.username, dbo.vehicles.id, dbo.vehicles.auditor, dbo.vehicles.auditnumber,
dbo.vehicles.auditstatus, dbo.vehicles.vinnumber, dbo.vehicles.dealerid,
dbo.vehicles.vehicleyear, dbo.vehicles.make, dbo.vehicles.model, dbo.vehicles.color,
dbo.vehicles.status, dbo.vehicles.cost, dbo.vehicles.currentbalanc
dbo.vehicles.mileage, dbo.vehicles.condition, dbo.vehicles.timeseen, dbo.vehicles.timeunseen,
dbo.vehicles.solddate, dbo.vehicles.purchaser, dbo.vehicles.imageurl, dbo.vehicles.datenow,
dbo.vehicles.totalunits, dbo.vehicles.checked, dbo.vehicles.totalbalance,
dbo.dealers.dealername, dbo.dealers.dealernumber, dbo.auditStatus.dispositio
dbo.auditStatus.descriptio
dbo.auditStatus.status AS Expr2, dbo.dealers.city, dbo.dealers.state,
dbo.dealers.id AS dealerid2
FROM dbo.auditors INNER JOIN
dbo.vehicles ON dbo.auditors.id = dbo.vehicles.auditor INNER JOIN
dbo.dealers ON dbo.vehicles.dealerid = dbo.dealers.id INNER JOIN
dbo.auditStatus ON dbo.vehicles.auditstatus = dbo.auditStatus.id
GROUP BY dbo.auditors.username, dbo.vehicles.id, dbo.vehicles.auditor, dbo.vehicles.auditnumber,
dbo.vehicles.auditstatus, dbo.vehicles.vinnumber, dbo.vehicles.dealerid,
dbo.vehicles.vehicleyear, dbo.vehicles.make, dbo.vehicles.model, dbo.vehicles.color,
dbo.vehicles.status, dbo.vehicles.cost, dbo.vehicles.currentbalanc
dbo.vehicles.mileage, dbo.vehicles.condition, dbo.vehicles.timeseen, dbo.vehicles.timeunseen,
dbo.vehicles.solddate, dbo.vehicles.purchaser, dbo.vehicles.imageurl, dbo.vehicles.datenow,
dbo.vehicles.totalunits, dbo.vehicles.totalbalance,
dbo.dealers.dealername, dbo.dealers.dealernumber, dbo.auditStatus.dispositio
dbo.auditStatus.descriptio
dbo.dealers.state, dbo.dealers.id)
SELECT ((SELECT COUNT(*)
FROM A
WHERE checked = 1) * 100 /
(SELECT COUNT(*)
FROM A)) AS CheckedPercentage
The % of vehicles checked overall? Or by dealer? Or by ...?
Here's how to add the overall % to every row:
SELECT dbo.auditors.username, dbo.vehicles.id, dbo.vehicles.auditor, dbo.vehicles.auditnumber, dbo.vehicles.auditstatus, dbo.vehicles.vinnumber,
dbo.vehicles.dealerid, dbo.vehicles.vehicleyear, dbo.vehicles.make, dbo.vehicles.model, dbo.vehicles.color, dbo.vehicles.status, dbo.vehicles.cost,
dbo.vehicles.currentbalanc
dbo.vehicles.solddate, dbo.vehicles.purchaser, dbo.vehicles.imageurl, dbo.vehicles.datenow, dbo.vehicles.totalunits, dbo.vehicles.checked,
dbo.vehicles.totalbalance,
dbo.auditStatus.descriptio
dbo.dealers.id AS dealerid2,
MAX(checkedPct) AS checkedPct
FROM dbo.auditors INNER JOIN
dbo.vehicles ON dbo.auditors.id = dbo.vehicles.auditor INNER JOIN
dbo.dealers ON dbo.vehicles.dealerid = dbo.dealers.id INNER JOIN
dbo.auditStatus ON dbo.vehicles.auditstatus = dbo.auditStatus.id CROSS JOIN
(SELECT SUM(CASE WHEN checked = 1 THEN 1 ELSE 0 END) * 100 / COUNT(*) AS checkedPct
FROM dbo.vehicles.checked) AS checkedPct
GROUP BY dbo.auditors.username, dbo.vehicles.id, dbo.vehicles.auditor, dbo.vehicles.auditnumber, dbo.vehicles.auditstatus, dbo.vehicles.vinnumber,
dbo.vehicles.dealerid, dbo.vehicles.vehicleyear, dbo.vehicles.make, dbo.vehicles.model, dbo.vehicles.color, dbo.vehicles.status, dbo.vehicles.cost,
dbo.vehicles.currentbalanc
dbo.vehicles.solddate, dbo.vehicles.purchaser, dbo.vehicles.imageurl, dbo.vehicles.datenow, dbo.vehicles.totalunits, dbo.vehicles.totalbalance,
dbo.vehicles.auditdate, dbo.vehicles.checked, dbo.dealers.dealername, dbo.dealers.dealernumber, dbo.auditStatus.dispositio
dbo.auditStatus.descriptio
Business Accounts
Answer for Membership
by: nkhelashviliPosted on 2009-02-10 at 04:28:15ID: 23599666
You can use this:
Select allOpen in new window