Hi nedash,
Refer the below sample query.
SQL
SELECT * FROM CustomersWithOutIdentity
SELECT CustomerId,Name
FROM (
SELECT DISTINCT CustomerId,Name,Country,ROW_NUMBER() OVER(ORDER BY Country ASC) CountryOrder
FROM (SELECT TOP 100 PERCENT CustomerId,Name,Country FROM CustomersWithOutIdentity WHERE CustomerId IS NOT NULL) b
)a ORDER BY CountryOrder
Input
| CustomerId |
Name |
Country |
| 1 |
Mudassar Khan |
Belgium |
| 2 |
Maria |
Austria |
| 3 |
Ana Trujillo |
France |
| 4 |
Antonio Moreno |
Brazil |
| 5 |
Thomas Hardy |
Ireland |
| NULL |
Test |
UK |
Output
| CustomerId |
Name |
| 2 |
Maria |
| 1 |
Mudassar Khan |
| 4 |
Antonio Moreno |
| 3 |
Ana Trujillo |
| 5 |
Thomas Hardy |
So you need to change you query like below.
SELECT Topic,TopicId
FROM (
SELECT DISTINCT TopicId,Topic,Preference,ROW_NUMBER() OVER(ORDER BY Preference ASC) PreferenceOrder
FROM (SELECT TOP 100 PERCENT TopicId,Topic,Preference FROM Documentry_Info WHERE Topic IS NOT NULL) b
)a ORDER BY PreferenceOrder