What interval is the current time of SQL Server?

Source: Internet
Author: User

Title: 24 hours a day different time period, the unit price of electricity is different, namely electricity price Gaoping Valley:

Peak: 9:00-12:00, 19:00-22:00 electricity price: 1.5 yuan per degree of electricity

Flat Peak: 8:00-9:00, 12:00-19:00, 22:00-24:00 Price: 1.0 yuan per degree of electricity

Gu Feng: 0:00-08:00 Price: 0.8 yuan per degree of electricity

The program executes the stored procedure every hour, and the stored procedure determines that the current time is the price of the Gaoping Valley SQL as follows:

 Declare @currentDateTime datetime; Declare @currentHour float; Declare @currentMinute float; Declare @ElectricityUnitPriceNumeric -,2);--Electricity Price                    Declare @Clock0 datetime; Declare @Clock8 datetime; Declare @Clock9 datetime; Declare @Clock12 datetime; Declare @Clock19 datetime; Declare @Clock22 datetime; Declare @Clock24 datetime; Set @currentDateTime=GETDATE(); Set @currentHour=DATEPART(Hour,@currentDateTime)--get current Time hours section          Set @currentMinute=DATEPART(MINUTE,@currentDateTime)                       Set @Clock0=Convert(datetime,Convert(varchar(Ten),@currentDateTime, -)+'00:00:000'); Set @Clock8=Convert(datetime,Convert(varchar(Ten),@currentDateTime, -)+'8:00:000'); Set @Clock9=Convert(datetime,Convert(varchar(Ten),@currentDateTime, -)+'9:00:000'); Set @Clock12=Convert(datetime,Convert(varchar(Ten),@currentDateTime, -)+'12:00:000'); Set @Clock19=Convert(datetime,Convert(varchar(Ten),@currentDateTime, -)+'19:00:000'); Set @Clock22=Convert(datetime,Convert(varchar(Ten),@currentDateTime, -)+'22:00:000'); Set @Clock24=Convert(datetime,Convert(varchar(Ten),@currentDateTime, -)+'23:59:000'); if(@currentHour=0) and(@currentMinute=0)--hours, minutes are zero, that is 24 points, flat peak end time            begin               Set @ElectricityUnitPrice=1.0;--Flat Peak Electricity price            End                  Else --not 24.           begin            if(@currentHour!=0) and(@currentMinute=0)--xxx dot whole             begin               Set @currentDateTime=DateAdd(Minute,- -,@currentDateTime);--the interval of the critical point equals the interval of the first half hour.             End                          if(@Clock0<@currentHour  and @currentHour<@Clock8)                   begin                     Set @ElectricityUnitPrice=0.8;--gu Feng electricity price                   End             Else if(@Clock8<@currentHour  and @currentHour<@Clock9)                  or(@Clock12<@currentHour  and @currentHour<@Clock19)                 or(@Clock22<@currentHour  and @currentHour<@Clock24)                 begin                    Set @ElectricityUnitPrice=1;--Flat Peak Electricity price                 End             Else if(@Clock9<@currentHour  and @currentHour<@Clock12)                    or(@Clock19<@currentHour  and @currentHour<@Clock22)                   begin                   Set @ElectricityUnitPrice=1.5;--Peak Electricity Price                 End             Else               begin                 --If the script is correct, it will not perform this step                 Set @ElectricityUnitPrice=-1; End          End

What interval is the current time of SQL Server?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.