When I execute the below code, the result is 0
:
cmd.CommandText = "select count(1) from dbc.tablesv where databasename = ? and TableKind in (?, ?) and tablename = ?";
cmd.Parameters.Add("db", TdType.VarChar).Value = dbName;
cmd.Parameters.Add("prc", TdType.VarChar).Value = objName;
cmd.Parameters.Add("p", TdType.Char).Value = 'P';
cmd.Parameters.Add("e", TdType.Char).Value = 'E';
if ((int)cmd.ExecuteScalar() == 0)
{}
But if I run the same query with the same values as supplied above, in Teradata Studio, then it returns 1
. This is on Teradata 17, client provider 17.0.2, and .NET full framework 4.7.2.
How am I supposed to pass parameters to a query through .NET connector, to receive correct results? It probably has something to do with IN
clause, because right before this failing query the same code that uses
select count(1) from dbc.TablesV where databasename = ? and tablename = ? and tablekind = ?
succeeds, with the correct result of 1
for a table that is related to the procedure I am looking for.
I confirmed that if both parameters of the IN
clause are hardcoded literals, then the query returns the correct results. If at least one of them is a parameter, then the query does not work.