MS SQL 2005: Any way to temporarily set the system date for a T-SQL script to a different date? - sql-server-2005

We have a bunch of T-SQL scripts dependent on today's date and when they run. If one doesn't run on the week it should, we end up temporarily setting the system time a day before, run the script, then set it back.
Is there anyway to temporarily set the system date for a script without changing the original script, like when you execute it or only for that session?

You could store the actual date in a table / temp table.
THen retrieve or update that date rather then making a call to GetDate().

I've found an answer by someone else, here I share it: "The date is tied to the OS date and time. See here: http://msdn.microsoft.com/en-us/library/ms188383.aspx".
You could refer to this other question Simulate current date on a SQL Server instance?

Related

Oracle Apex - selecting date with different hours

We have a web application which we store a date from the user. The date is stored on an Oracle 19c database as a date field.
The problem we have is that when we select the date it's coming with different hours, like it's taking into account the timezone or something. So, for example one person can see the date 2021-05-20T13:00:00Z while another somewhere else can see 2021-05-20T12:00:00Z.
Is there a way to prevent this behavior, and have everybody get the same date and time?
Update
Most likely the problem resides in Oracle Apex, not Oracle database!
We use a very old version of Apex, 1.x it seems so maybe this problem doesn't happen on newer versions.
That is often problem when you use, for example, java.util.Timezone,java.sql.Date or java.util.Date type in java instead of oracle.sql.Date

Is there any workaround to get host_time in SQL Server 2012?

I know there is a system function to get the host name - which returns the Server Name (Application server name in my case).
SELECT HOST_NAME()
Is there a similar function like HOST_TIME() to get the time of application server?
Or is there any workaround at database side to get the time of application server when a procedure is called?
This doesn't sound like a database question to me. You should have the application pass along a timestamp along with whatever query is getting sent along to the database server.
If you must define this at the database level, why don't you simply add the time zone difference? I'm not sure where you're located, though here in the US if I had that issue I would simply do at GETDATE() and then use DATEADD to adjust to the timezone of the other table. The only thing which you would need to spend some time on would be what to do when the time changes (daylight savings time etc.). In my case, none of our users use our system at that hour, though that may be different in your case.
Good luck, and let us know what happens.

Is there a way to set a nullubule Timstamp2 back on null?

I have in a table a nullubule timestamp that tracks when the entry got called from a client. Sometimes something goes wrong on the client side and I need to set the timestamp back to null. I tried directly in SQL management studio to execute the query:
USE [MyDB]
GO
UPDATE [dbo].[MyTable]
SET [MyTimestamp]=null
WHERE ID=SomeInt;
I get the message that one row got altered but when I refresh my select * on the table there is no change on the timestamp.
PS: The whole DB runs on an azure server but I can also not get it to work on my test DB on local host in SQL Server 2014.
Would be grateful for input 
The answer is you cannot change the timestamp column to NULL. It is like a row version number.
Also
The timestamp data type is just an incrementing number and does not
preserve a date or a time.
There are some workarounds which you can use as the one which is used here in the related thread but now Timestamp datatype is rarely used.

How to determine when a SQL Subscription was marked for re-initialization?

MS SQL Server 2012
I am trying to determine when a subscription was marked for reinitialization. I can see when the subscription started to reinitialize, but I want to see at what time the command was issued to reinitialize the subscriptions.
I have looked in the syssubscriptions table, there is a timestamp column, but that is not actually a time. Any way to determine in the sql logs or a modified datetime somewhere else?
Timestamp refers to the date and time that the subscription was created.
I just tested and you can get it from subscription_time value in your distribution database metadata like so:
select publisher_db, subscriber_db, subscription_time, *
from distribution.dbo.MSsubscriptions
where subscriber_id >=0
-Chuck

SQL Server 2005 - Mailqueues use UTC time instead of local time

This is more of a question than a problem as our production system is working as intended.
I am relatively new to the SQL environment. I've been poking through various configurations on the server just to get myself familiarized with the system. One thing that I noticed is the mail queues seem to use the UTC time instead of the local time. For example, if I run
exec sysmail_help_queue_sp
The last empty_rowset_time column shows a time that is exactly 12 hours behind the value getdate() returns (I am in New Zealand) and happens to coincide with the value of getutcdate(). I was more than a little surprised to say the least. The server is configured with the correct time zone (Auckland/Wellington).
I have made sure that the value(s) in the last_empty_rowset_time is indeed updated every time I sp_send_dbmail.
Does anyone know why this is the case? I am just curious to know. I do apologize for my newbiness if this sounds obvious to some of you.
Thanks.
James
This isn't something that is affected by local configuration. Based on documentation here:
http://msdn.microsoft.com/en-us/library/ms187400.aspx
Microsoft explicitly states "military time format and GMT time zone". If you want to see it in your local time zone you'll have to modify your query as such.