SQL First select a value

SELECT     AssetValue
FROM         Assets
WHERE     (AssetType = 'Country')

A very simple Select statement, but it prints

Afghanistan
Albania
Algeria
....

How can I make the USA and Canada appear on top of this? Is this possible with SQL or do I need to do something in my ASP code? My PK is the identifier of INT.

+5
source share
3 answers
SELECT     AssetValue
FROM         Assets
WHERE     (AssetType = 'Country')
ORDER BY CASE AssetValue 
          WHEN 'US' THEN 1 
          WHEN 'Canada' THEN 2 ELSE 3 END, AssetValue 
+21
source

If you do not want hard code, the most general solution has an additional field for specifying preferred elements. You would call him OrderPreference. The higher the OrderPreference, the first the item will be. Each else element has an OrderPreference of ZERO. Inquiry:

SELECT     AssetValue
FROM         Assets
WHERE     (AssetType = 'Country')
ORDER BY OrderPreference desc, AssetValue

, Assets - , ( ), , .

+4

Give them the group identifier, so group 1 is the USA, UK, etc., group2 is the rest of the world, then you can make “priority” countries.

+1
source

All Articles