获取@StartAt和@NumberResults的选项。我在上的注释中使用了一个从Adam的最终代码中派生出来的表,根据我的经验,它比实际的表快,占用的空间也少。my bad。我使用MS SQL Server在任何时候添加的记录数是否有上限和下限?你有没
获取@StartAt和@NumberResults的选项。我在上的注释中使用了一个从Adam的最终代码中派生出来的表,根据我的经验,它比实际的表快,占用的空间也少。my bad。我使用MS SQL Server在任何时候添加的记录数是否有上限和下限?你有没,sql,sql-server,datetime,stored-procedures,dateadd,Sql,Sql Server,Datetime,Stored Procedures,Dateadd,获取@StartAt和@NumberResults的选项。我在上的注释中使用了一个从Adam的最终代码中派生出来的表,根据我的经验,它比实际的表快,占用的空间也少。my bad。我使用MS SQL Server在任何时候添加的记录数是否有上限和下限?你有没有试过的代码?dateadd(h,2,previousDate)总是从当前日期9点开始是的。这是一种自动预约的程序。其中开始时间为第二天上午9:00,根据输入参数,每个记录将增加2小时。最小值为1,最大值为6My bad。我使用MS SQL S
获取@StartAt和@NumberResults的选项。我在上的注释中使用了一个从Adam的最终代码中派生出来的表,根据我的经验,它比实际的表快,占用的空间也少。my bad。我使用MS SQL Server在任何时候添加的记录数是否有上限和下限?你有没有试过的代码?dateadd(h,2,previousDate)总是从当前日期9点开始是的。这是一种自动预约的程序。其中开始时间为第二天上午9:00,根据输入参数,每个记录将增加2小时。最小值为1,最大值为6My bad。我使用MS SQL Server在任何时候添加的记录数是否有上限和下限?你有没有试过的代码?dateadd(h,2,previousDate)总是从当前日期9点开始是的。这是一种自动预约的程序。其中开始时间为第二天上午9:00,根据输入参数,每个记录将增加2小时。最小值为1,最大值为6
12/20/2015 9:00
12/20/2015 11:00
12/20/2015 13:00
12/20/2015 15:00
12/20/2015 17:00
DECLARE @RecordsRequired INT = 5;
DECLARE @BaseDateTime SMALLDATETIME = GETDATE();
WITH [Sample] AS
(
/* This CTE uses recursion to create the required number of
* records.
*/
SELECT
1 AS RowNumber,
@BaseDateTime AS [DateTime]
UNION ALL
SELECT
RowNumber + 1 AS RowNumber,
DATEADD(HOUR, 2, [DateTime]) AS [DateTime]
FROM
[Sample]
WHERE
RowNumber < @RecordsRequired
)
SELECT
RowNumber,
[DateTime]
FROM
[Sample]
;
------------------ INPUT ------------------------
declare @start_date datetime = '01/01/2000 14:00'
declare @loops int = 5
-------------------------------------------------
declare @i int = 0
while (@i < @loops) begin
select dateadd(hour, @i * 2, @start_date)
set @i = @i + 1
end
Declare @count int = 5,
@incrementer int =2 -- in case if you want to change the incrementer
SELECT Dateadd(hh, num * @incrementer, dates)
FROM (SELECT Cast(CONVERT(VARCHAR(20), Dateadd(dd, 1, Getdate()), 111)
+ ' 9:00 AM' AS DATETIME) AS Dates,
num
FROM (VALUES(0),(1),(2),(3),(4),(5)) TC (num)) A
WHERE num <= @count - 1
Create Table dates
(
datetimefield datetime not null
)
go
Create Procedure FillDateTimeField
@insertxrows int
AS
begin
Declare @LastDateTimeInserted as datetime
set @LastDateTimeInserted = (select isnull(max(datetimefield),getdate()) from Dates)
;WITH norows AS (
SELECT 1 as num, Dateadd(hour,2,@LastDateTimeInserted) as FirstRecord
UNION ALL
SELECT num + 1, dateadd(hour,2,firstrecord) FROM
norows
WHERE num < @insertxrows
)
insert into dates
select firstrecord from norows
end
--Create a temp table for sample output
CREATE TABLE #temp
(
CreatedDate datetime
)
--Declaring variables
DECLARE @Count int
DECLARE @TimeCounter int
--intializing values
SET @Count=5
SET @TimeCounter=0
WHILE(@Count>0)
BEGIN
--SELECT getdate()+1
insert into #temp(#temp.CreatedDate) Select DATEADD(hour,@TimeCounter,getdate())
SET @TimeCounter=@TimeCounter+2
SET @Count=@Count-1
END
--Final values
SELECT * FROM #temp tmp
--Dropping table
DROP TABLE #temp
CREATE PROCEDURE usp_PopulateAppointments
(
@StartDateTime datetime2(3),
@Records int,
@Interval int = 120 --Time between appointment slots in minutes. Default to 2h if not manually specified.
)
INSERT INTO Appointments
SELECT
DATEADD(m, @Interval * Number, @StartDateTime)
FROM dbo.udfNumbers(0, @Recs)