Jump to content

SELECT para data atual


Marianna Gonçalves
 Share

Recommended Posts

Boa tarde,

Tenho uma procedure que puxa esses dados:

SELECT TOP 100

COD_PACIENTE,

NOME,

RG,

CPF,

NUM_CARTAO,

DIA_NASC,

MES_NASC,

ANO_NASC,

IDADE,

SEXO,

ENDERECO,

TELEFONE1,

TELEFONE2,

EMAIL,

BAIRRO,

CIDADE,

NATURALIDADE,

NOME_MAE,

PRONTUARIO,

DT_ATUALIZACAO,

NOME_PAI,

OCUPACAO,

ESTADO_CIVIL,

GRAU_INSTRUCAO,

COR,

RG_UF,

DT_CADASTRO,

USUARIO_CAD

FROM [sGH]..[sYSTEM].[PACIENTES]

WHERE

Queria puxar todos esses dados no meu sistema filtrando pela "DT_ATUALIZAÇÃO" a data atual, como faço?

Link to comment
Share on other sites

Boa tarde,

Passas para dentro da procedure um parametro.

static void getPacientes(string connectionString,
   string categoryName)
{
   using (SqlConnection connection = new SqlConnection(connectionString))
   {
    // Cria um comando e define as propriedades
    SqlCommand command = new SqlCommand();
    command.Connection = connection;
    command.CommandText = "tuaStoredProcedure";
    command.CommandType = CommandType.StoredProcedure;
    // Adicona o parametro e define as propriedades dele
    SqlParameter parameter = new SqlParameter();
    parameter.ParameterName = "@DT_AGORA";
    parameter.SqlDbType = SqlDbType.DateTime;
    parameter.Direction = ParameterDirection.Input;
    parameter.Value = DateTime.Now; //valor da data e hora actuais do sistema
    //Adiciona o parametro à colecção de parametros
    command.Parameters.Add(parameter);
    // abre a conecção e executa o reader
    connection.Open();
    SqlDataReader reader = command.ExecuteReader();
    //whatever
    reader.Close();
}
}

Provávelmente vais ter de alterar ligeiramente a tua stored procedure para suportar o parametro

SELECT TOP 100
COD_PACIENTE,
NOME,
RG,
CPF,
NUM_CARTAO,
DIA_NASC,
MES_NASC,
ANO_NASC,
IDADE,
SEXO,
ENDERECO,
TELEFONE1,
TELEFONE2,
EMAIL,
BAIRRO,
CIDADE,
NATURALIDADE,
NOME_MAE,
PRONTUARIO,
DT_ATUALIZACAO,
NOME_PAI,
OCUPACAO,
ESTADO_CIVIL,
GRAU_INSTRUCAO,
COR,
RG_UF,
DT_CADASTRO,
USUARIO_CAD
FROM [sGH]..[sYSTEM].[PACIENTES]
WHERE DT_ATUALIZACAO = @DT_AGORA

Cordiais cumprimentos,

Apocsantos

"A paciência é uma das coisas que se aprendeu na era do 48k" O respeito é como a escrita de código, uma vez perdido, dificilmente se retoma o habito"

Link to comment
Share on other sites

Correndo o risco de já vir muito tarde , mas mesmo assim...

Não precisas de alterar o SP para receber um parametro... se esse SP usa sempre com a data actual (Hoje) então podes usar o "Getdate()" do SQL..

Apenas tens que garantir que obtens apenas a data sem a hora, pois nesse caso não deves conseguir nenhum resultado..

Algo assim:

SELECT *
FROM [sGH]..[sYSTEM].[PACIENTES]
WHERE DT_ATUALIZACAO = CONVERT(date, getdate())
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.