2
In my project, I have a SELECT
which brings me back two names, but these names are different. On my command, I need to return these two different names that are in the same column of the bank in a tag of a xml that I’m creating.
How could I make a method that would recognize these two names in c# and return them to me?
The way I got it here, it returns only one.
I’m gonna put my SELECT
to help!
SELECT *
FROM TabelaPessoa
INNER JOIN TabelaRegistro ON PessoaCodCasamentoCodigo = CasamentoCodigo
INNER JOIN LocalCasamento ON LocalCasamentoCodigo = CasamentoCodigo
LEFT JOIN CasamentoRegime ON RegimeCodigo = CasamentoCodigo
LEFT JOIN Infomacao ON InformacaoCodigo = CasamentoCOdigo
WHERE NomePessoa = 'Fulano' OR
NomePessoa = 'Fulana'
AND CodigoTipoPessoa IN (1, 7)
EDIT
Codes C#
that I have:
try
{
string sqlPesquisa = "";
sqlPesquisa = "SELECT * \n" +
"FROM TabelaPessoa INNER JOIN TabelaRegistro ON \n" +
" PessoaCodCasamentoCodigo = CasamentoCodigo INNER JOIN LocalCasamento ON \n" +
" LocalCasamentoCodigo = CasamentoCodigo LEFT JOIN CasamentoRegime ON \n" +
" RegimeCodigo = CasamentoCodigo LEFT JOIN Infomacao ON \n" +
" InformacaoCodigo = CasamentoCodigo \n" +
"WHERE NomePessoa = " + tabela + " OR \n" +
" NomePessoa = " + tabela + " AND \n" +
" CodigoTipoPessoa IN (1, 7)";
DataTable pesquisa = executarPesquisa(sqlPesquisa);
return (pesquisa);
}
Put the code in C# of your method too so someone can help you.
– LucasMotta
I don’t see any problem with the code. I think it is the case of making a SQL Fiddle to validate the data.
– Leonel Sanches da Silva
Why do you do
+ tabela +
? You’re passing the same name and comparing it twice in the same way... there’s something wrong– Maicon Carraro
@Gypsy Rhythmandmendez what happens is that at the time of returning me the data, I say the names, only returns me one of the names, and repeats it
– Érik Thiago
+ tabela +
is the table value I want the data to come!– Érik Thiago
So. Put the data in SQL Fiddle and let’s see what happens.
– Leonel Sanches da Silva
The tricky thing is that there are several tables I have here, and I do the
joins
in them. There are 4 tables.– Érik Thiago
His code has "+ table +" twice, he is looking for the same name twice. Also, as Fernando answered, parentheses are missing... AND has preference over OR. Thus, OR B AND C is the same thing as A OR (B AND C).
– RSinohara