In Mongo DB , How to get the inital date of data insertion - mongodb-query

I entered many data in MongoDB on different dates,
for example
from January, each day I entered data, how to know which date I started data insertion process

I think that there is no way to find that out, a workaround for that is you can alter your table and add a timestamp column, with default value now().
That let you see when future inserts are created.

Related

Is it possible to store a variable (int) in SQL to then take effect once a certain date has been reached?

Is it possible to store a variable in a SQL table which will only take effect once a certain date is reached? The variable is the amount of days that would be added to a date to create a "TargetDate", this variable can be changed by user input but must have an "EffectiveDate" ?
You can certainly create a configuration table that you store config data in. In your case, one of the items would be 'EFCTV_BUFFER' as the value in the key column, and (for an example) '5' as the number of days in the value column. Then you can reference that key value to select the buffer days value, and add that to whatever date you want.
This allows you to modify it at any time as requested.
You would reference this table in an insert/update trigger on your table where you store your dates. I would suggest having two dates so that the calculation is only done once, unless you need the calculation to be dynamic based upon the current 'EFCTV_BUFFER' configuration value.

date and time not being added to table with correct default and datatype

I am using AnySQL Maestro 13.2.0.15 which is SQL-server based. I need the date and time to automatically be put in the column "added" of my table called "accntgs" with out me having to select the current date and time. I have added the field with the datetime data type and set the default to getdate(), but then when I enter a new record and post it, the added field is still null. I have also tried to use the timestamp data type, and when I post a new record with that, the added field says (bytes) and does not have the date or the time. How do I fix this and get the date and time the record is posted to show up.
I have also tried this:
ALTER TABLE accntgs ADD CONSTRAINT
DF_accntgs_added DEFAULT GETDATE() FOR added
and it didnt add the the date when the new record was posted either

Derived date calculation

I am currently entering data into a SQL Server database using SSIS. The plan is for it to do this each week but the day that it happens may differ depending on when the data will be pushed through.
I use SSIS to grab data from an Excel worksheet and enter each row into the database (about 150 rows per week). The only common denominator is the date between all the rows. I want to add a date to each of the rows on the day that it gets pushed through. Because the push date may differ I can't use the current date I want to use a week from the previous date entered for that row.
But because there are about 150 rows I don't know how to achieve this. It would be nice if I could set this up in SQL Server where every time a new set of rows are entered it adds 7 days from the previous set of rows. But I would also be happy to do this in SSIS.
Does anyone have any clue how to achieve this? Alternatively, I don't mind doing this in C# either.
Here's one way to do what you want:
Create a column for tracking the data entry date in your target table.
Add an Execute SQL Task before the Data Flow Task. This task will retrieve the latest data entry date + 7 days. The query should be something like:
select dateadd(day,7,max(trackdate)) from targettable
Assign the SQL result to a package variable.
Add a Derived Column Transformation between your Source and Destination components in the Data Flow Task. Create a dummy column to hold the tracking date and assign the variable to it.
When you map the Excel to table in a Data Flow task, map the dummy column created earlier to the tracking date column. Now when you write the data to DB, your tracking column will have the desired date.
Derived Column Transformation

SQL - how to add every day a new column in 1 query without INSERT, UPDATE, etc

I need to add every day to some query result a column A for sysdate, and next day as well, and next day as well, etc.
So you will have the same select which will always add for new day a new column for actual date.
Is this somehow possible in sql without using INSERT, UPDATE and other rewriting statements?
Thank you very much for your answers :)
Im using a Oracle SQL Developer
SQL queries give you a fixed number of columns and a variable number of rows. If every day means more data to you then you would have a query to result in more rows usually. It's up to a GUI to display retrieved data in the most convenient way (one column per day in your example).
So, yes and no. Yes, you can (very easily) write a query to give you more data each day. No, you cannot write a query that results in a new column every day. But as mentioned, this is not what SQL is made for anyhow. SQL is the data retrieving language. You use a programming language or a report tool to display the data to your users.

SQL Default Constraint

I have a table with 2 columns dateRecieved and dateDue. I know how to make the dateNow column show today's date by default by using:
DEFAULT GETDATE()
The user can then modify the dateRecieved column to whatever date they want.
After the user modifies the dateRecieved column; how do I set up the dateDue column so that it, by default, shows a date x days away from dateRecieved?
I looked at this answer but I need to refer to another column.
Need to add constraint: date plus 10 days
Is there a way that dateRecieved can modify its value automatically when dateRecieved changes?
The user should be able to override the default values in both these columns.
I'm using the W3 schools sql tutorial but it didn't have and answer I couldn't find one on stackoverflow either
http://www.w3schools.com/sql/sql_default.asp
use current date as default value for a column
Thanks
So when you say the "user modifies" you are talking about an UPDATE.
DEFAULT values are relevant to INSERT statements only.
It is true you can accomplish whatever automagical UPDATE change you want via triggers but as a beginner, I would squarely advise you away from triggers. They are rarely implemented correctly and make understanding when things go wrong more difficult.
What you want to do is INSERT your row(s) (allowing any DEFAULT values to "happen") and then UPDATE your row(s) with the values you intended.
It sounds like what you're looking for is a trigger that waits until the update is finished, then the dateDue automatically updates.
This answer may point you in the right direction:
How to: Create trigger for auto update modified date with SQL Server 2008