0
Hello, I have a problem that I can not solve. I want to make a SELECT
at the base using the command IN(@grupo)
. Where the @group is a string with the ids separated by comma Exp(1,2,4). However when I run sql it only considers the first value (1) and not all values.
this is the SQL I’m using
public List<PedidoPDVMODEL> BuscaGrupoDistribuidores(string grupo)
{
SuportePDV s = new SuportePDV();
//cria uma lista para os parametros
List<SuportePDV.SQLParametro> parametros = new List<SuportePDV.SQLParametro>();
parametros.Add(new SuportePDV.SQLParametro("@grupo", grupo));
//monta a query
string query = "SELECT SUM(total) AS total, dt_pedido " +
"FROM tpedido " +
"WHERE IN(@grupo) AND YEAR(dt_pedido) > 2015 AND dt_cancela = '0000-00-00' " +
"GROUP BY MONTH(dt_pedido), YEAR(dt_pedido) " +
"ORDER BY dt_pedido";
DataTable tabela = s.RetornaDataTable(query, parametros);
List<PedidoPDVMODEL> lista = new List<PedidoPDVMODEL>();
if (tabela.Rows.Count == 0)
return lista;
try
{
foreach (DataRow item in tabela.Rows)
{
PedidoPDVMODEL g = new PedidoPDVMODEL
{
dt_pedido = Convert.ToDateTime(item["dt_pedido"].ToString()),
total = Convert.ToDecimal(item["total"].ToString()),
mes = Convert.ToDateTime(item["dt_pedido"].ToString()).Month,
ano = Convert.ToDateTime(item["dt_pedido"].ToString()).Year
};
lista.Add(g);
}
return lista;
}
catch (Exception ex)
{
MessageBox.Show("Erro: " + ex.Message, "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
}
you will need to construct this parameter with the tab and do the processing in Mysql. Present the code c# of how you are doing the query
– Leandro Angelo
Thank you for answering, where I can enter the code for you to view. I’m new here, I haven’t yet gotten the hang of it
– Julio Cesar
I edited the post with the code I’m using. I get a string "group", and it has the group ids I want to search for
– Julio Cesar