Add one new record to query (1 Viewer)

jaryszek

Registered User.
Local time
Today, 03:02
Joined
Aug 25, 2016
Messages
756
hi The_Doc_Man,

thank you! Nice approach.
Then make its record ID the first record using that order.

if i will set up flag how can i set this record as first?
for example it will be ID = 987 with flag = "Yes".

What is working for me is:

SELECT 1 AS SortKey, Table1.TableName
FROM Table1
ORDER BY Table1.TableName
UNION
SELECT 0 AS SortKey, "Tab3" AS TableName FROM Table1
order by SortKey

I will get here Tab3 as first occurence.

Jacek
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:02
Joined
Feb 28, 2001
Messages
26,996
If you wanted the flagged record to always be first, make the flag a BYTE integer, not a Yes/No field, and make the flag 0 for your header and 1 for "natural" data. Call it "NaturalFlag" or sometime simpler to type. Then for the recordset that contains the header, use ORDER BY NaturalFlag, SortKey. Since 0 comes before 1, this "special" record will come first. But it is the ONLY record with that value, so everything that follows will be "natural" records in the order of your sort key.
 

jaryszek

Registered User.
Local time
Today, 03:02
Joined
Aug 25, 2016
Messages
756
Thank yuo very much The_Doc_Man
 

Users who are viewing this thread

Top Bottom