Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Using CTE to populate records

$
0
0

Hi,

I have a table called Periods:

Period

=============

Period 0-1 days

Period 1-2 days

Period 2-3days

I need to cross join this table to another table (CTE) such that the resultant will be 5 Periods (i.e. upto Period 4-5), total of 7200 rows (5 periods X 24 hours X 60 minutes) :

Period                        Days           Minutes

=====

Period 0-1 days          00

Period 0-1 days          01

..

Period 0-1 days     0                  1439

Period 1-2 days   11440

Period 1-2 days          2                   1

I'm thinking of using a CTE to propagate the Days and Minutes. But I could not achieve what I need. I'm not sure how to continue from here. Note: nums table contains a sequential numbers.

with ctemin as (select N from nums where N < 7200)

select a.period1, b.N\24 as days, b.N\24\60 as mins

from periods1 a

cross join ctemin b

Please help!


cherriesh


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>