Click here to Skip to main content
15,881,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a query that is taking much time.
Please help How to optimize this one.I have already created index. Below is the code.


SQL
SELECT  ISNULL(dbo.Note.notCaseId,0) AS CaseID,
   ISNULL(CONVERT(varchar(20),dbo.Note.notNoteDate,103),'') AS NoteDate,
   ISNULL(dbo.Note.notDescription,'') AS NoteDescription,
   ISNULL(dbo.GetRealUserName(dbo.aspnet_Users.UserName),'') AS NoteUserName
 FROM    dbo.Note INNER JOIN
   dbo.aspnet_Users ON dbo.Note.notUserId = dbo.aspnet_Users.UserId
 WHERE dbo.Note.notCaseId IN (Select casCaseId From [case]  INNER join [CaseServiceTypeMapping] on [Case].casCaseID= csrvCaseId
inner join [CaseServiceType] on csrvServiceTypeId= cstyServiceTypeID AND IsGlobal=1  Where casCreateDate BETWEEN 'Apr  1 2012 12:00AM' AND 'Apr  3 2013 12:00AM' ) ORDER BY dbo.Note.notNoteDate DESC
Posted

hi,

you can try below sql

SQL
SELECT  ISNULL(dbo.Note.notCaseId,0) AS CaseID,
   ISNULL(CONVERT(varchar(20),dbo.Note.notNoteDate,103),'') AS NoteDate,
   ISNULL(dbo.Note.notDescription,'') AS NoteDescription,
   ISNULL(dbo.GetRealUserName(dbo.aspnet_Users.UserName),'') AS NoteUserName
 FROM    dbo.Note
 INNER JOIN dbo.aspnet_Users ON dbo.Note.notUserId = dbo.aspnet_Users.UserId
 INNER JOIN [case] ON [case].casCaseId = dbo.Note.notCaseId
 INNER join [CaseServiceTypeMapping] on [Case].casCaseID= csrvCaseId
  inner join [CaseServiceType] on csrvServiceTypeId= cstyServiceTypeID AND IsGlobal=1
        AND casCreateDate BETWEEN 'Apr  1 2012 12:00AM' AND 'Apr  3 2013 12:00AM'
ORDER BY dbo.Note.notNoteDate DESC



I can't run this sql without your db, so please run and inform me if you found any issue.


One more thing if you want a date hardcode then don't use this 'Apr 1 2012 12:00AM' format because if sql server default date format is differ than this format then its not work. Instead of this formate you can use yyyyMMdd.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900