Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL command works in Oracle not in MS SQL?

Status
Not open for further replies.

ASmee

IS-IT--Management
Jul 9, 2002
46
US
select count(distinct exposureid) from iinstrumentidmaster where exposureid in (select exposureid from iinstrumentidmaster group by exposureid having count(exposureid) >1) order by exposureid

Can't work out why! MS SQL is not my speciality.
 
Sorry, I forgot that bit!

An ORDER BY clause is invalid in views, derived tables, and subqueries unless TOP is also specified.

Same occurs on MS SQL 7 and 2000.
 
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

-SQLBill
 
Ok, tried it and yet the following:

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top