[AccessD] SQL Server - selecting preferred records

jwcolby jwcolby at colbyconsulting.com
Thu Nov 4 20:41:56 CDT 2010


Yea, I was afraid the union was going to creep in.

John W. Colby
www.ColbyConsulting.com

On 11/4/2010 7:16 PM, Stuart McLachlan wrote:
> Something like this?
>
> Select top 540000 from
>
> (select 1 as seq, RecordPK from table1
> where  (Children_0_3 and income in(XYZ))
> or (Children_4_7 and income in(XYZ))
> Order by Seq
> ....
> UNION
> select 2 as seq, RecordPK from table1
> where  (Age in (1,2) and income in (ABC)))
>
>
>
> On 4 Nov 2010 at 10:51, jwcolby wrote:
>
>> I have a query where I need to select sets of records:
>>
>> (Children_0_3 and income in(XYZ))
>> (Children_4_7 and income in(XYZ))
>> .
>> .
>> etc.
>> (Age in (1,2) and income in (ABC))
>>
>> I need to select the first group, then the next etc until I total 540K
>> records.
>>
>> Basically I need to select the records with something in any of the
>> Children_X_Y fields and after that select from the last group.
>>
>> Is there a way to do that directly in SQL?
>>
>>
>> --
>> John W. Colby
>> www.ColbyConsulting.com
>> --
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/accessd
>> Website: http://www.databaseadvisors.com
>>
>
>



More information about the AccessD mailing list