This is my temporary table :
CREATE TABLE #tmpRecentTxns(SerialID nvarchar(50) null,TranDate datetime2 null)
select *
from #tmpRecentTxns
where #tmpRecentTxns.SerialID NOT IN
(SELECT distinct Phone
FROM ApplicationVariables
WHERE datediff(n, vardatetime, getdate()) <= 300)
Here Phone datatype is nvarchar(10) in database.
Problem : when I am going to select value it is taking too much time.
Please help me out how to remove this problem.
Thanks in advance.
I don’t think the fact your
Phoneis of typeNVARCHAR(10)is the reason for poor performance.First of all, you should make sure you have an index on the
vardatetimecolumn in yourApplicationVariablestable (including thePhonecolumn).Second, you should change the query so that this index can be used:
Also: I would recommend to use the
MINUTEspecifier forDATEDADDorDATEDIFF– much clearer what you’re trying to do.