Function :
create function .[data_by_date_district](@rev_datetime datetime)
returns table
as
return
(
SELECT
ro.Region,[DATETIME],
sum(datain) 'datain',
sum(dataout) 'dataout'
FROM
data.inoutdata cr
join
structure.site ro on
ro.site = substring(replace([siteunqid],'**',''),1,LEN(siteunqid)-1)
where [DATETIME] =@rev_datetime
group by Region,[DATETIME]
);
Executing this function with any date takes 00:00:00.
Now when I join this with another table it takes 4 sec (this table is 75 rows) :
SELECT
Region,[DATETIME],datain,dataout,(cr.datain+cr.dataout) 'total',SP_GEOMETRY,MI_STYLE,MI_PRINX
FROM
data.data_by_date_district(DATEADD(DAY,-1,cast(GETDATE() as DATE)) ) cr
join
datamap.VectorMaps.REGION_BND db
on db.Name = cr.Region
The first table has 1,700,000 rows of data which increases daily by 170,000 but other table has just 75 rows. Is there any way i could decrease the query time? The result of function is 75 rows.