June 20, 2019 at 1:16 pm
We have a Data base we migrated to 2014 from 2008, everything is working fine except we have a stored proc that has the following
it just hangs, but if I replace the parameter in the select statement with getdate() it works. or if i change the compatibility mode to 2008.
when I am debug and hover over the @today I can see it is properly set to todays date. very very strange
Declare @today datetime
Set @today = getdate()
select * from table where insertdate < @today
June 20, 2019 at 1:58 pm
This might have to do with what SQL Server would expect as a Default value, GetDate()'s Default Value is non existent so precompiling query plans (which is what sp's are supposed to do in order to work faster than plain, dynamic queries.
You could try some sort of approach like this instead:
ALTER PROC DisplayDate
(
@DateVar DATETIME = NULL
) AS
BEGIN
set @DateVar=ISNULL(@DateVar,GETDATE())
--the SP stuff here
SELECT @DateVar
END
GO
June 20, 2019 at 2:13 pm
--Deleted
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
June 20, 2019 at 3:02 pm
my question is why does it work with compatibility mode 2008 not with comparability mode 2014?
because I have 100's of procs that use the declare @today datetime
June 20, 2019 at 3:04 pm
my question is why does it work with compatibility mode 2008 not with comparability mode 2014? because I have 100's of procs that use the declare @today datetime
Can you provide a self-contained example which demonstrates this, so that we can verify it too?
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
June 20, 2019 at 3:19 pm
I'm guessing this has to do with the new Cardinality Estimator that was introduced with SQL Server 2014.
We've seen some strange goings on with this feature if the statistics aren't quite up-to-date. So I'd try to first instruct SQL Server to use the old Cardinality Estimator by adding OPTION(QUERYTRACEON 9481) to the query.
If the query runs as expected with this trace flag set, you know it's the Cardinality Estimator that makes SQL Server choose a bad execution plan (like doing a table scan instead of doing an index seek).
You might also try to update the statistics on the table and see if that changes anything.
June 20, 2019 at 3:30 pm
good suggestions i will take a look.
June 25, 2019 at 10:38 am
Thanks for the help using OPTION(QUERYTRACEON 9481) , corrected the issue I also tried option (recompile) and it worked also. so the Cardinality Estimator is a new feature to 2014, to help pick a better excursion plan?
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply