0
During my studies, I tried to sort the records and put those that are NULL
in the end, I did it this way:
SELECT
tbl1.firstname,
tbl1.mgrid
FROM
(
SELECT TOP 100 firstname, mgrid
FROM HR.Employees
WHERE mgrid IS NOT NULL
ORDER BY mgrid
) tbl1
UNION ALL
SELECT
tbl2.firstname,
tbl2.mgrid
FROM
(
SELECT TOP 100 firstname, mgrid
FROM HR.Employees
WHERE mgrid IS NULL
ORDER BY mgrid
) tbl2
I had no interest in putting the TOP
, but found that when using a query inside the FROM
, it is mandatory to put the TOP
(at least in the version I use), it happens that the TOP
expects a quantity parameter, but I do not have a fixed quantity, so I would like to know if there is something like SELECT TOP all
.
Thank you!
I’ve never seen TOP mandatory in a sub-select, explain it better there
– Rovann Linhalis
i also do not believe it is necessary. But you can use the modifier
PERCENT
to specify that you want a percentage, not a fixed number. Then just doSELECT TOP (100) PERCENT
.– Phiter
Gabriel, in the sub-sale TOP was requested because you put ORDER BY in it.
– José Diz