Mohammad Alsolaiman
asked on
crosstab query takes more than 5 minutes rendering data
Hi:
I have a crosstab query which take over 5 minutes rendering data
Table 1 : @TempTable has 1100 records.
Table 2 : Days table has 30 records which is days numbers from 1 to 30 (Arabic month)
--this is my query:
SELECT FullData.day, a.DailyAttendanceID
,FullData.BSC_NO
,bsc_name = FullData.bsc_name
,a .BSC_UNIT
,a .BSC_SECTION_NO
,a .DailyAttendanceTypeID
, PTDattendanceCodes = isnull (a .PTDattendanceCodes,'-')
,a .DailyAttendanceDescriptio ns
,a .WhoCreated
,a .AttendanceDate
,a .GetDate
,a .myTime
,a .IsFingerPrintExists
,a . myDay
FROM
(select * from Days
CROSS JOIN
(SELECT DISTINCT [BSC_NO],bsc_name from @TempTable) as Data ) as FullData
LEFT JOIN
@TempTable as a on FullData.day = a.myDay
AND FullData.[BSC_NO] = a.[BSC_NO]
order by FullData .BSC_NO , FullData .day
any idea please
my output result is like what U C in here:
I have a crosstab query which take over 5 minutes rendering data
Table 1 : @TempTable has 1100 records.
Table 2 : Days table has 30 records which is days numbers from 1 to 30 (Arabic month)
--this is my query:
SELECT FullData.day, a.DailyAttendanceID
,FullData.BSC_NO
,bsc_name = FullData.bsc_name
,a .BSC_UNIT
,a .BSC_SECTION_NO
,a .DailyAttendanceTypeID
, PTDattendanceCodes = isnull (a .PTDattendanceCodes,'-')
,a .DailyAttendanceDescriptio
,a .WhoCreated
,a .AttendanceDate
,a .GetDate
,a .myTime
,a .IsFingerPrintExists
,a . myDay
FROM
(select * from Days
CROSS JOIN
(SELECT DISTINCT [BSC_NO],bsc_name from @TempTable) as Data ) as FullData
LEFT JOIN
@TempTable as a on FullData.day = a.myDay
AND FullData.[BSC_NO] = a.[BSC_NO]
order by FullData .BSC_NO , FullData .day
any idea please
my output result is like what U C in here:
ASKER
unfortunately, my query was faster with around 30 seconds. Thank my friend for trying helping me.
can you share the execution plan for both yours and my queries?
ASKER
see attached execution plan Execution-Plan--1.sqlplanExecution-Plan--Expert.sqlplan
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window