I have two parts of a query, which are causing it to run very slowly.
Is there another way I could rewrite these parts?
Part One - looks at the last fullmonth, the system starts at 1970 with regards to dates.
WHERE Fieldname >= DATEDIFF(second, '1970-01-01', DATEADD(DAY, - DAY(GETDATE()) + 1, CONVERT(CHAR(8), DATEADD(MONTH, - 1, GETDATE()), 112))) AND Fieldname < DATEDIFF(second, '1970-01-01', DATEADD(DAY, - DAY(GETDATE()) + 1, CONVERT(CHAR(8), GETDATE(), 112)))
Part Two - second part of above Where statement.
Can you create an index on the field below and then drop it at the ned, or is there a better way of doing this as I think this is related to the field not being indexed
WHERE callingPartyLoginUserID IN ( 'username1', 'username1', 'username3' etc)