|
Posted by Erland Sommarskog on 04/05/06 00:19
(jannoergaard@hotmail.com) writes:
> As I recall the statement it's something like this
>
> Select distinct dbo.Account.AccountNo as AccountNo
>>From dbo.Account inner join dbo.Groups
> On dbo.Groups.AccountFrom <= dbo.Account.AccountNo AND
> dbo.Groups.AccountTo >= dbo.Account.AccountNo
>
> Hope you have a solution for me. I have tried different ways but don't
> seme to get it right.
This is certainly better, since it relieves you from the DISTINCT:
SELECT a.AccountNp
FROM dbo.Account a
WHERE EXISTS (SELECT *
FROM dbo.Groups g
WHERE a.AccountNo BETWEEN g.AccountFrom AND g.AccountTo)
But whether that really addresses your issue, I cannot tell, because
your posting was very clear.
If this query does not work out, I suggest that you post the following:
o CREATE TABLE statements for your tables.
o INSERT statements with sample data.
o The desired result from the sample.
This permits anyone who wants to answer to copy and paste into
a query tool and develop a tested query.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|