SQL Spreads can create drop-down lists that let
the user select a text value from another table but SQL Spreads will insert the
key value into the updated table.
In this demo we have a table with cities which has columns for the city name and the country code. We would like the user to be able to select the full country name in a drop-down list instead of entering the country code. You can download the demo here Drop-down List Demo.
Drop-down lists must be setup using the Advanced Setup. The
easiest way to use the Advanced Setup is to start with selecting a table in the
Designer, and then go into the Advanced Setup and do further modifications.
- Select the Cities table in the SQL Spreads Designer. This will load the table into Excel, and also create a Database Import
- Go to the Advanced Setup and select Database Mapping
- Select the Cities Database Mapping in the list and click Edit.
- Click Yes to accept switching from the Designer to the Advanced Setup:
- We would like to add the drop-down list in the CountryCode column. To do so, click the Add button in the rightmost column for the CountryCode row:
- The dialog for creating the drop-down list is shown. a. First, select the referenced table to fetch the drop-down list values from (Countries). b. Then select which column in the referenced table that contains the key values (the CountryCode). c. Lastly select which column from the referenced table that should be shown in the drop-down list (The country name in the Name column):
- Click Ok in all three dialogs to get back to Excel.
- We also need to update the import so that the Country name is shown in Excel, instead of the Country Code. We do that by updating the import SQL query that loads data into the spreadsheet. Go to the Advanced Setup and click the Database Import:
- Then select the Cities Database Import and click Edit:
- In the import SQL query we will have to join the Cities table
with the Countries table. Then we need to replace the CountryCode column with
the country name from the joined Countries table:
[SQLSpreadsDemo].[dbo].[Cities] AS [Cities]
[SQLSpreadsDemo].[dbo].[Countries] AS [Countries] ON [Countries].[CountryCode] = [Cities].[CountryCode]
- Click Ok three times to go back to Excel.
- To update the spreadsheet with the new settings, click the Refresh button. You will now see the drop-down list showing the country name. If you select a new country and click Save, the county code for the selected country will be stored in the Cities table: