0

How do I select certain set of data(rows) from sql database by the time when they are inserted? I don't see any related documents in regards to how to do this using mssql module in node.js... could anyone suggest me any reading material or something else? So my question is how to create timestamp column when data are inserted in database

Thank you

Zlatko Loa
  • 149
  • 1
  • 5
  • 13
  • Is it mssql or mysql? you tagged mysql and in your question description it is mssql. – Deep Kakkar Nov 24 '17 at 06:20
  • Therte is a bigger problem here, which is that I'm not sure your question actually has anything to do with Node. AFAIK in MySQL and SQL Server if you want to keep track of when a record was inserted, you would need to maintain a column for that. Have you maintained such state in your table? – Tim Biegeleisen Nov 24 '17 at 06:22
  • That was sort of my question. Should I maintain a column which tracks the row data? I was thinking that too but I couldn't find any documents how to start that.. – Zlatko Loa Nov 24 '17 at 06:30
  • it is mssql. I will update the tag, didn't seem there is a tag called mssql.. – Zlatko Loa Nov 24 '17 at 06:30

1 Answers1

0

The doc seem straight forward on how to achieve it

const sql = require('mssql')

async () => {
    try {
        const pool = await 
sql.connect('mssql://username:password@localhost/database')
        const result = await sql.query`SELECT * FROM TABLE WHERE DATE BETWEEN '09/16/2010 05:00:00' and '09/21/2010 09:00:00'`
        console.dir(result)
   } catch (err) {
       // ... error checks
   }
}
Lewix
  • 924
  • 1
  • 9
  • 11
  • How does your query identify records based on the time they were inserted? – Tim Biegeleisen Nov 24 '17 at 06:24
  • @Lewix, how do I create timestamp in database when the data are inserted? I don't have any column that tracks the timestamp. I know how to take the time from database and read corresponding data, but I guess my question was more how to create timestamp in sql server – Zlatko Loa Nov 24 '17 at 06:43
  • @ZlatkoLoa it was not your question - you just updated it and it completely changed. – Lewix Nov 24 '17 at 07:20
  • @ZlatkoLoa as for your new question about inserting with a default timestamp. refer to https://stackoverflow.com/questions/168736/how-do-you-set-a-default-value-for-a-mysql-datetime-column – Lewix Nov 24 '17 at 07:23