Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SELECT TOP with UNION

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-11-06 : 07:35:50
Alan writes "I have a SQL statement, that I call from VB:

SELECT A, B, C
FROM TableA
WHERE ...
UNION
SELECT X as A, Y as B, Z as C
FROM TableB
WHERE ...
ORDER BY A

THIS WORKS FINE but I've now switched to using ADO and the MaxRecords doesn't work anymore, so I'd like to use SELECT TOP

However, if I change the two SELECT statements above to eg
SELECT TOP 8 ...
...
UNION
SELECT TOP 8 ...
...

I get more than 8 records back

If this was a stored procedure I could use SET ROWCOUNT 8 instead of SELECT TOP 8 but I call this straight from VB to populate a recordset.

Please give me some advice.

Many thanks
Alan"

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-11-06 : 07:38:22
Make you unioned queries a derived table and then select top 8 from that ...

Jay White
{0}
Go to Top of Page
   

- Advertisement -