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

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.

Related

SQL Server: computed column to allow for adjustments?

I have a computed column known as TotalTime. This column is populated using the DATEDIFF function from two datapoints that we are getting entered in from Microsoft PowerApps - StartTime and EndTime.
However, sometimes it would be nice to be able to make adjustments to the calculation. For example, if the PowerApps user selects a certain control, it would add five minutes to TotalTime.
This doesn't necessarily have to come from PowerApps itself - but could be a stored proc or function. What is the cleanest way to do this without having to break the computed column?
Add a new column (TotalTimeAdjustment) reserved for admin adjustment. This will be normally NULL (or can be defaulted to 0). Modify your calculated column to include TotalTimeAdjustment column as the 3rd input alongside StartTime and EndTime. Whenever an adjustment is needed the admin can update TotalTimeAdjustment for the relevant record(s).

Insert Date and Time columns in SSRB

I am attempting to generate a report that will have data automatically inserted into it from a server. Normally, I insert a variable from fields in the data set and run the report. However, the task I have been given is to insert date/time columns with every value column and report builder doesn't seem to like that. It inserts a single date/time column on the far left and then all the values. If I try to put a date/time column in between values, it pushes that column to the far right/last column.
It should go
datetime,value1,
datetime,value2...
and so on.
At present it goes like
datetime,value1,value2...datetime.
Is this achievable?
And if so, how can I do this?

Create a historical sequence in talend big data jobs

I have a requirement to create sequence in talend.
Basically records are coming from a source file.
for each source row i want to create a unique number.
here is where it gets complicated.
when a new file comes next day , the talend should pick the last generated number and then increment it with 1.
for EX:
today the last generated sequence number is 100.
tomorrow the talend should generate sequence number from 100 . i.e. 101,102,103,104.....
This means talend should keep the history of previously generated last sequence number.
Thanks
So, in such a case you have to persist this last sequence value somewhere, in the target database (if any) or in a dedicated file.
If the records are stored in a database, you can also get the max value from the corresponding field using the appropriate Select.
When you got the desired value, you need to store it in a global variable, then reuse this variable to initialize the sequence with something like:
Numeric.sequence("yourSequence", (Integer)globalMap.get("yourGlobal"), 1)Hope this helps.

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

How to add a record to a table

I would like to create an control on embedded on a continuous form of which its activation event creates a new record on the form and inserts today's date in the date field. I was thinking to use an SQL query to create the record but still am having difficulty.
Maybe you should try this...
In the table being inserted into, add a field called "date_entered" and have its default
value set to "Now()". This will give you a timestamp (knowledge of when the record was entered).
Doing it this way is the easiest way, and then you don't have to write any extra code.