I am attempting to query my table which has the schema:
CREATE TABLE [dbo].[FIN_MeetingDisplay-DefaultConfig](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](150) NOT NULL,
[value] [nvarchar](max) NOT NULL
)
Two values in the table store a time when Power Saving should be enabled or disabled:
EnablePowerSave 10:00PM
DisablePowerSave 08:00AM
What I am wanting to do is query the table to see if the current time is between the EnablePowerSave and DisablePowerSave window.
I am currently querying it with the following, which is always returning false which is because it is using today’s date. What would be the best way to change the query so that if it is after 8am to use tomorrow’s date and before 8am to use today’s date?
SELECT CONVERT(DATETIME, CAST(GETDATE() AS VARCHAR(11)) + ' ' + VALUE, 103)
FROM dbo.[FIN_MeetingDisplay-DefaultConfig]
WHERE name = 'EnablePowerSave'
Thanks,
Matt
This implies some assumed knowledge – that Enable time is on day one and Disable time is always the following day, and you are always running the query on the following day.