I have a procedure that has following functions in where
condition:
select col1,col2,col3...
from table1
where
(dbo.GetFilStatus(et.SgDate,et.Speed,(SELECT COUNT(J.JId) FROM tbl_Nt J
inner JOIN tbl_NAssign JN ON JN.NNo =J.NNo
inner JOIN dbo.tbl_CStatus JS ON JS.CStatusID=J.CStatusID
INNER JOIN dbo.tbl_SStatus ss ON ss.SStatusID=JS.SStatusID
WHERE JN.DriID=et.DriID AND ss.SStatusID !=9),et.IgStatus)
in (Select val from Split('A,B,C,D,E',',')))
)
getfilstatus status contains the following code:-
if (@ServerDatetime <= DATEADD(MI,-10, GETDATE()))
BEGIN
IF(@xIgStatus = 'ON')
BEGIN
set @FilStatus= 'NoSignal'
END
ELSE
BEGIN
set @FilStatus= 'Stopped'
end
End
else IF(@xIgStatus = 'ON')
Begin
if(@Speed>5)
begin
if(@JCount<=0)
set @FilStatus='Moving'
else
set @FilStatus='Working'
end
else
begin
set @FilStatus= 'Idle'
end
End
else
Begin
set @FilStatus= 'Stopped'
end
RETURN @FilStatus
GetFilStatus
always returns more than 10000 records. Sometimes its more than 100000. Its slowing the final output of query. Currently its taking more than 2 mins to return the output.
I am searching for any other option or any other trick using which the query performance can be increased and I could get the output in seconds.
Any suggestions? Any ideas?