E
E
Evgeny Bogdanov2016-10-13 12:40:06
Transact SQL
Evgeny Bogdanov, 2016-10-13 12:40:06

How to get time values ​​in Select from values?

Hello, there was a need to get date - time values ​​using The result should look like this: 2016-10-13 00:00 2016-10-13 00:01 2016-10-13 00:02 ... It is desirable that the value of the date could be specified by yourself. Thank you in advance for your help!
SELECT * FROM VALUES

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-10-13
@besp0ke

This is for dates, it is not at all difficult to remake it in the form you need.

CREATE FUNCTION [dbo].[GetDateRangeShort] (@StartDate datetime, @EndDate datetime)
RETURNS @Res TABLE (Date datetime) AS
BEGIN
    ;WITH MyEmp (Date, Level)
    AS(
      SELECT @StartDate, 1
      UNION ALL
      SELECT DATEADD(dd, 1, Date), Level + 1
      FROM MyEmp
      WHERE (Date < @EndDate)
    )
    INSERT INTO @Res (Date) SELECT Date FROM MyEmp OPTION (MAXRECURSION 0);

  RETURN
END

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question