Sort field or expired date notifications, database

Asked

Viewed 399 times

1

I know nothing about database, I’m using one in Visual Studio (the standard SQL called "Service-based database"), I’ve integrated it into the form and made up the query fields.

But there is a field of one of the tables that would date, that date is like a 'loan', and it expires (one week from now, as an example).

Then comes the doubt (I researched and found nothing about it).

The question is:

How do I order a table of this database by the data, showing the field records of the data older to younger?

Another doubt (this is more advanced), but the first one is enough for me (I am humble kk), it’s like, this field of data, as I said, it’s like loan, so I wanted to know, taking example the record:

"Nome: José", "Data do empréstimo: 23/06/2015"

In this table, as I stimulated the due date is one week, the maturity would be today, so how to take this database record and store it in a variable (to be displayed in another form)?

The other field:

"Nome: João", "Data do empréstimo: 24/06/2015"

The expiration would be tomorrow, so tomorrow he would send this record to the other form automatically, as if it were an expiration notice.

  • 1

    How is the structure of your table, this deadline is what type? And how are you doing to call the queries via c#?

  • The structure asks for name, contact, borrowed item.. The term is type datetime. The query I did according to this video -> https://www.youtube.com/watch?v=Qt0z2ySimV8 (because I really know nothing about this, practicing is what you learn)

  • 1

    then you have the loan date column and deadline? in the term you save date type loan + 1 week?

  • Yes, exactly

2 answers

1


at first just sort the dates you can use order by.

Ex: SELECT * FROM usuarios ORDER BY dataemprestimo ASC

descfor decreasing and asc to ascend, how much to catch the expiry date, in the function Load form, you can call a function to do this, you can create an instruction sql to get it in the bank something like:

Ex: SELECT * FROM usuarios where dataemprestimo > datalimite

so you would have all the records that exceeded the deadline, detail, to work that query you need a field that is stored the deadline for the user to return the product, simple thing to do on insertand on the schedule when registering.

Note: if you give me the name of the tables I put here the function.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   notificarUsuarios()
End Sub

 Private Sub notificarUsuarios()
 se quiser apenas armazenar 1 data, mais vc pode jogar em um datagrid
     Dim nomeDoUsuario As String = nomeDataSet.Tables("usuarios").Rows(0)("usuario")
     Dim dataVencida As String = nomeDataSet.Tables("usuarios").Rows(0)("dataexpira")
 End Sub
  • The names are the same usuarios and the name of the table, and the dataemprestimo and datalimite the fields datetime right? Only the datalimite who ta dataexpira in mine (this I have learned from so much looking at the codes generated by Visual kk)

  • only one Obs, you need to put the instruction sql in the dataset that you will use, for this click with the right on DataSet, va in Configure... and add this query: SELECT * FROM usuarios WHERE dataemprestimo > dataexpira ORDER BY dataemprestimo ASC is at your discretion to call all fields with * or just the fields nomeusuario and datalimite,

1

If you want the OLDEST date and not the NEWEST one, you want ascendant and not descending.

SELECT * FROM Emprestimo
ORDER BY dataemprestimo ASC

Sqlfiddle Example

About your second problem, you can use the Sql Server variable to get the current day and time GETDATE().

That way in a table the losers is:

SELECT * FROM Emprestimo
WHERE datalimite <= GETDATE()
ORDER BY dataemprestimo ASC

And on the table those who haven’t won yet are:

SELECT * FROM Emprestimo
WHERE datalimite > GETDATE()
ORDER BY dataemprestimo ASC
  • Hence these commands are inserted in the table file right? '-'

  • In the video you sent is at 0:35 where it adds the query

Browser other questions tagged

You are not signed in. Login or sign up in order to post.