select count(distinct exposureid) from iinstrumentidmaster where exposureid in (select exposureid from iinstrumentidmaster group by exposureid having count(exposureid) >1) order by exposureid
I don't understand why you are getting that error since you only have one ORDER BY and it's not in the subquery; you aren't using a view, and it doesn't appear to be part of a derived table.
However, give this a try:
select count(distinct exposureid)
from iinstrumentidmaster
where exposureid in (select TOP 100 PERCENT exposureid from iinstrumentidmaster group by exposureid having count(exposureid) >1)
order by exposureid
Column name 'iinstrumentidmaster.exposureid' is invalid in the ORDER BY clause because it is not contained in an aggregate function and there is no GROUP BY clause.
select count(distinct exposureid) from iinstrumentidmaster where exposureid in (select exposureid from iinstrumentidmaster group by exposureid having count(exposureid) >1)
You are returning a single value here so there is no point in having an order by clause.
I think the same query is
select count(*)
from (select exposureid from iinstrumentidmaster group by exposureid having count(*) > 1) a
======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.