问题
I have an Excel file that's basically a query result to a database server.
I linked one sheet of this Excel file as an external table from within a MS Access database.
This external "Excel table" has a set of columns representing optional parameters.
I want to create one "all_parameters" query result field that represents a semicolon-separated list of all non-null parameters as "parameter name: parameter value" tuples. In this case, "parameter name" is also the name of the column in which the parameter value is to be found.
Imagine the following table:
id param_foo param_bar param_baz
1 a
2 b c
3
I hope to create a MS Access query that generates the following field:
id parameter_list
1 param_foo: a
2 param_bar: b; param_baz: c
3 (null)
What does NOT work, is this:
SELECT
id,
Iif([param_foo]="Null";"";"; param_foo: "&[param_foo])
& Iif([param_bar]="Null";"";"; param_bar: "&[param_bar])
& Iif([param_baz]="Null";"";"; param_baz: "&[param_baz]) AS all_parameters
FROM
my_table
;
Any help is more than welcome.
回答1:
Silly me.
MS Access requires commas as parameter separator, not semicolons.
Hence the following query works:
SELECT
id,
Iif([param_foo]="Null", "", "; param_foo: "&[param_foo])
& Iif([param_bar]="Null", "", "; param_bar: "&[param_bar])
& Iif([param_baz]="Null", "", "; param_baz: "&[param_baz]) AS all_parameters
FROM
my_table
;
Problem solved.
来源:https://stackoverflow.com/questions/32589086/ms-access-combine-non-null-column-values-into-a-column-name-column-value-te