
上QQ阅读APP看书,第一时间看更新
Select columns
- Use the Table.SelectColumns() function to accomplish the following:
- Explicitly define the only columns retrieved
- Set the presentation order of the columns in the Query Editor
- Avoid query failure if one of the source columns changes or is missing
- In this example, 29 columns are available from the AdventureWorks Customer Dimension table, but only 11 are selected

Figure 64: The Expression for Selecting Columns
- The MissingField.UseNull parameter is optional but recommended
- If a column selected isn't available or is renamed in the source database, the query will still succeed (see Figure 65):

Figure 65: Columns from the expression in Figure 64 viewed in the Query Editor interface
- The columns are presented in the Query Editor in the order specified
- This can be helpful for the query design process, and avoids the need for an additional expression with a Table.ReorderColumns() function

Figure 66: Missing Field Null Values
- In this example, the source system column was renamed to AnnualIncome. Rather than the query failing, null values were passed into this column.
- Create a name column from the first and last names via Table.AddColumn().
- Add a final Table.SelectColumns() expression that excludes the FirstName and LastName columns.

Figure 67: Customer Name Expression
- The MissingField.UseNull parameter isn't needed for this expression since it was already used in the Table.SelectColumns() function against the source.

Figure 68: Revised Customer Name Column
- Columns representing an attribute in other languages such as SpanishEducation and FrenchOccupation are excluded.
- The type of the Customer Name column should be set to text (type text) in the Table.AddColumn() function.