Query on a column with different values

2

In my project, I have a SELECT that returns me two names, but those names are different. In my command, I need to return these two different names that are in the same column of the database in an tag of an xml I am creating.

How could I make a method that recognizes these two names in and return them?

The way I have it, it returns me only one.

I'll put my SELECT here 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# 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);
        }
    
asked by anonymous 26.06.2015 / 15:13

2 answers

3

Your never command will return two different names because you are only searching for ONE name, and the name you are searching for comes from a variable named tabela . Your command should be:

 where 
     ( NomePessoa = '" + Nome_1 + "' OR NomePessoa = '" + Nome_2 + "' )
 AND ( CodigoTipoPessoa in (1,7) ) 

where

 Nome_1 = 'Fulano'
 Nome_2 = 'Fulana'

And only so-and-so will list that CodigoTipoPessoa is between 1 and 7

    
26.06.2015 / 16:41
1

I would recommend separating the name into two columns in your database. An alternative, considering two names:

string doisNomes = "Fulano Sicrano";
string[] arrayDeDoisNomes = doisNomes.Split(' ');
string nomeUm = arrayDeDoisNomes[0]; // aqui está "Fulano"
string nomeDois = arrayDeDoisNomes[1]; // aqui está "Sicrano"

The Split method receives a char (or a string) as a delimiter, a character that identifies the "cut". In the example above I used a space.

    
26.06.2015 / 15:54