How to search in one table by date and add values contained in it?

1

This is personal, I'm having a hard time creating a date search in my android sqlite database. I wanted to search the tables by date, if possible, I wanted to do a conditional that would detect the current date, and only update the table (adding certain values) not needing to create new tables.

From now on I thank you greatly for giving me a "light" on this question.

My table is this:

CREATE TABLE IF NOT EXISTS ENTRADA (

    _id                INTEGER       NOT NULL
                                     PRIMARY KEY AUTOINCREMENT,
    DATA                DATE         NOT NULL DEFAULT CURRENT_DATE,
    SALDO               VARCHAR (20),
    DEPOSITO            VARCHAR (20),
    ECONOMIAS           VARCHAR (20),
    SALARIODOMES        VARCHAR (20),
    
asked by anonymous 23.04.2016 / 19:21

2 answers

1

Hello, I think you're looking for something like this:

SQL SERVER

    UPDATE TABELA_A SET VALOR = X+Y
        WHERE DATA = GETDATE() 

or Oracle

    UPDATE TABELA_A SET VALOR = X+Y
        WHERE DATA = SYSDATE()

The condition you make to check is in the WHERE or UPDATE AND clause itself. Take a look at the following link that might help you.

link

    
24.04.2016 / 05:45
0

Use the Calendar Class to get and record the day, month, and year. Convert to String and write to String in the database. Use double for the value (non-comma point). "Create table ... _ id INTEGER ... d (for the day) text + m (month) .. y (year) all" TEXT ", leave the value" double "in the table creation

// In the Class where you do the search use

private SQLiteDatabase database;

// then ...

public void somando() {
   Cursor cursor;
cursor = database.rawQuery("SELECT SUM(valor) FROM nomeDaSuaTabela WHERE d = ? AND m = ? AND y = ?",new String[] { dia, mes, ano });
//obtenha do sistema os valores da data ou de um EditText 
        if (cursor.moveToFirst()) {
                    double total = cursor.getDouble(0);// o argumento é o int
                                                        // indice da coluna

                    mensagemExibir(
                            "Total",
                            "A Soma do Valor doQueVcQuer do dia "
                                    + dia
                                    + " de "
                                    + mes
                                    + " de "
                                    + ano
                                    + " é de\n R$ "
                                    + String.valueOf(String.format("%.2f",
                                            total)));

                }
public void mensagemExibir(String titulo, String texto) {
        AlertDialog.Builder mensagem = new AlertDialog.Builder(
                SuaClasseContexto.this);
        mensagem.setTitle(titulo);
        mensagem.setMessage(texto);
        mensagem.setNeutralButton("OK", null);
        mensagem.show();
        mensagem.setCancelable(true);

    }

Play the method by adding () inside the event of a Button. In the message you can also use a NumberFormat.getCurrencyInstance (). Although if you are to edit after any typing error the android usually rounds the doubles after the point. Then you have to roll over if you want a lot of precision. Abs

    
27.04.2016 / 04:14