SELECT on column value = X but if no rows available then any column value In MSSQL 2016 enterprise edition I have a table column which can contain an int. I'd like to query for 1000 rows where this column equal X, but if no rows then column may contain any value.

Eg:

SELECT TOP 1000 COLS FROM TABLE WHERE  &lt;COL = 4 OR IF NO ROWS THEN COL = ANY VALUE&gt;


How do I write the logic within &lt; and >
Obtain non-'col=X' only if 'col=x' not exists:

SELECT TOP 1000 *
FROM table
WHERE col = CASE WHEN EXISTS (SELECT 1
                              FROM table
                              WHERE col = X)
                 THEN X
                 ELSE col
            END


Obtain 1000 records, 'col=X' first:

SELECT TOP 1000 *
FROM table
ORDER BY CASE WHEN col = X 
              THEN 0
              ELSE 1 END