Quantcast
Channel: SCN : Unanswered Discussions - Data Services and Data Quality
Viewing all articles
Browse latest Browse all 3719

Cross join on big tables

$
0
0

hi guys

I need to create cross join between two big tables, in which Frist table contains (25333012) and second table contains (5259167)... because of huge data data flow is not getting completed.. First table contains schedule timings where as second table contains appointment associated with schedule id and needs to retrieve the vacant time slots from the first table for each day...

 

see the sample data below:-

 

see the sample data :-


CREATE TABLE #t (id INT,strt_time datetime, end_time datetime)--- first table

INSERT INTO #t VALUES (101,'1900-01-01 09:30:00.000','1900-01-01 09:30:05.000')
INSERT INTO #t VALUES (101,'1900-01-01 09:35:00.000','1900-01-01 09:35:05.000')
INSERT INTO #t VALUES (101,'1900-01-01 09:35:00.000','1900-01-01 09:35:05.000')
INSERT INTO #t VALUES (101,'1900-01-01 09:40:00.000','1900-01-01 09:40:05.000')
INSERT INTO #t VALUES (101,'1900-01-01 09:45:00.000','1900-01-01 09:45:05.000')

select * from #t


CREATE TABLE #t2 (id INT,appt_dt date, strt_time datetime)--- second table

INSERT INTO #t2 VALUES (101,'2015-01-08','1900-01-01 09:30:00.000')
INSERT INTO #t2 VALUES (101,'2015-01-08','1900-01-01 09:35:00.000')
INSERT INTO #t2 VALUES (101,'2015-01-08','1900-01-01 09:35:00.000')
INSERT INTO #t2 VALUES (101,'2015-05-08','1900-01-01 09:40:00.000')
INSERT INTO #t2 VALUES (101,'2015-05-08','1900-01-01 09:45:00.000')
INSERT INTO #t2 VALUES (101,'2015-05-08','1900-01-01 09:45:00.000')
INSERT INTO #t2 VALUES (101,'2015-05-18','1900-01-01 09:30:00.000')
INSERT INTO #t2 VALUES (101,'2015-05-18','1900-01-01 09:35:00.000')
INSERT INTO #t2 VALUES (101,'2015-05-18','1900-01-01 09:40:00.000')
INSERT INTO #t2 VALUES (101,'2015-05-18','1900-01-01 09:45:00.000')

select * from #t2

 

CREATE TABLE #t_res (id INT,appt_dt date, strt_time datetime)--- result expected

INSERT INTO #t_res VALUES (101,'2015-01-08','1900-01-01 09:40:00.000')
INSERT INTO #t_res VALUES (101,'2015-01-08','1900-01-01 09:45:00.000')
INSERT INTO #t_res VALUES (101,'2015-05-08','1900-01-01 09:30:00.000')


select * from #t_res

 

 

Is there any better way to achieve same..

Regards


Viewing all articles
Browse latest Browse all 3719

Trending Articles



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