I am running a stored procedure in SQL Server, something like:
INSERT INTO #TempTable
SELECT CustomerID
FROM Customer
WHERE DateCreated > @TimeStamp
This is ignoring the index on the date column. I run the select query it is fine with a parameter, I change to this it is fine:
INSERT INTO #TempTable
SELECT CustomerID
FROM Customer
WHERE DateCreated > '20150122'
I changed the whole query to dynamic SQL and now it runs fine too.
What is happening here?