Xaphann
Xaphann

Reputation: 3677

BigQuery BigQueryParameter and parameterize where fields

What is the correct way to parameterize the field name in the Where statement?

My app dynamically creates Where based on the user's input. Therefore I want to parameterize not only the values but the fields. When I do no results are given. I want to be clear, not an error just 0 rows returned.

List<BigQueryParameter> parameters = new List<BigQueryParameter>()
parameters.Add(new BigQueryParameter("MyValue", BigQueryDbType.String, value));
parameters.Add(new BigQueryParameter(fieldName, BigQueryDbType.String, fieldName));
var sqlCmd = $"Select * from myProject.myDataset.myTable where @{fieldName} = @MyValue";
var queryResults = await _client.ExecuteQueryAsync(sqlCmd, parameters);

If I remove the @ in front of fieldName the query works and returns the desired data;

List<BigQueryParameter> parameters = new List<BigQueryParameter>()
parameters.Add(new BigQueryParameter("MyValue", BigQueryDbType.String, value));
parameters.Add(new BigQueryParameter(fieldName, BigQueryDbType.String, fieldName));
var sqlCmd = $"Select * from myProject.myDataset.myTable where {fieldName} = @MyValue";
var queryResults = await _client.ExecuteQueryAsync(sqlCmd, parameters);

edit: add a bit more code for readability

Upvotes: 0

Views: 673

Answers (1)

Mr.Batra
Mr.Batra

Reputation: 833

Parameters cannot be used as substitutes for identifiers, column names, table names, or other parts of the query.

Read it here - Documentation C# Example

Upvotes: 2

Related Questions