Using the data from the Shape file example, a variety of
queries can be constructed. The examples below use the new CAST and CONVERT
features of SQL Server 2008 to 'format' HEX characters for colorizing the results.
Top 10 by population
/* Shade countries by population (solid red is highest) */
DECLARE @max FLOAT -- Find the highest value
SELECT @max = MAX(pop_cntry) FROM cntry00
SELECT TOP 10 -- Choose how many to view
long_name
, geog
, '#' + CONVERT (VARCHAR(MAX)),
CONVERT (VARBINARY(MAX), CAST (ROUND ((pop_cntry/@max * 255), 0) AS TINYINT) )
, 2) + 'FF0000' AS [Fill] -- set alpha/opacity and RED color
, '0' AS [Thickness]
FROM cntry00
ORDER BY pop_cntry DESC
Shape tab
Map tab
Of course, the population of Alaska is somewhat overstated at this level of granularity!
All countries by population
/* Shade countries by population (solid red is highest) */
DECLARE @max FLOAT -- Find the highest value
SELECT @max = MAX(pop_cntry) FROM cntry00
SELECT -- View all
long_name
, geog
, '#' + CONVERT (VARCHAR(MAX)),
CONVERT (VARBINARY(MAX), CAST (ROUND ((pop_cntry/@max * 255), 0) AS TINYINT) )
, 2) + 'FF0000' AS [Fill] -- set alpha/opacity and RED color
, '#88FF0000' AS [Color] -- set outline color
, '0.25' AS [Thickness]
FROM cntry00
ORDER BY pop_cntry DESC
Shape tab
Map tab
Landlocked countries
/* Shade countries by 'landlocked' status */
SELECT long_name
, geog
, CASE WHEN Landlocked = 'Y' THEN
'#FF00FF00' -- landlocked are green
ELSE
'#FF0000FF' -- seaside are blue
END AS [Fill]
, '0' AS [Thickness]
FROM cntry00
Shape tab