0

example :

INPUT :

column1 column2 
10:00am 11:00am   

I have to get like the below output

OUTPUT:

column1 column2 
10:00am 10:15am 
10:16am 10:20am 
10:21am 10:30am 
10:31am 10:40am 
10:41am 10:50am 
10:51am 11:00am
dbajtr
  • 2,024
  • 2
  • 14
  • 22
Yamini
  • 1
  • 1
  • 2
    Which DBMS do you use? – Jens Jun 21 '17 at 08:11
  • please clarify how the rest of the data is calculated – Dimgold Jun 21 '17 at 08:13
  • This Post Explain you in detail, prefer to create a function for future use https://stackoverflow.com/questions/5123585/how-to-split-a-single-column-values-to-multiple-column-values – Ven Jun 21 '17 at 08:15
  • I need to split that 2 columns , output will be like column1 column2 10:00am 10:15am 10:16am 10:20am 10:21am 10:30am 10:31am 10:40am 10:41am 10:50am 10:51am 11:00am – Yamini Jun 21 '17 at 08:31
  • 1
    there is no increment pattern, first row + 15, second + 5, third and so on +10 ...? – Pawel Czapski Jun 21 '17 at 08:39
  • Please tag with the actual RDBMS (product and version) and please read [How to ask a good SQL question](http://meta.stackoverflow.com/questions/271055/tips-for-asking-a-good-structured-query-language-sql-question/271056) and [How to create a MCVE](http://stackoverflow.com/help/mcve) – Shnugo Jun 21 '17 at 08:41
  • I don't understand the logic behind the increments –  Jun 21 '17 at 09:15

2 Answers2

1

Your expected output is not all clear...

Your first intervall is 15 minutes, the rest is 10 minutes.

You can try it like this (which is strictly 10 minutes - SQL Server syntax):

DECLARE @Start TIME='10:00';
DECLARE @End TIME='11:30';
DECLARE @minuteIncrement INT=10;

WITH Tally AS
(
    SELECT TOP ((DATEDIFF(MINUTE,CAST(@Start AS DATETIME),CAST(@End AS DATETIME)))/@minuteIncrement) (ROW_NUMBER() OVER(ORDER BY (SELECT NULL))-1) * @minuteIncrement AS Nr 
    FROM master..spt_values
)
SELECT CAST(DATEADD(MINUTE,Nr+1,@Start) AS TIME) AS column1  
      ,CAST(DATEADD(MINUTE,Nr+@minuteIncrement,@Start) AS TIME) AS column2  
FROM Tally;

If you really need the first intervall differently, you'll have to start the calculated value with the first strict intervall and add the first step with UNION ALL...

Shnugo
  • 66,100
  • 9
  • 53
  • 114
-1

You can use (SELECT column1 FROM db) UNION (SELECT columns2 FROM db)