N
N
Noob_0012015-05-18 15:45:00
SQL
Noob_001, 2015-05-18 15:45:00

SQL data type ... ....?

The question means artful...
Let's admit there is a request for selection in very big base for 1 day.
- 7 tables.
- 3 tables with a condition for one and the same date (so as not to pull too much). ps there is no date in other tables.
(dates in tables of type - datetime)
2 solutions:
1) figurative example:
declare @d1 datetime
declare @d2 datetime
set @d1 = '02/05/2015'
set @d1 = '03/05/2015'
select sum(t.price * t.val) from test t
innrer ...
innrer ...
innrer ...
where
t.date between @d1 and @d2 and
t2.date between @d1 and @d2 and
t3.date between @d1 and @d2
. ..
2) Figurative example:
select sum(t.price * t.val) from test t
innrer ...
innrer ...
innrer ...
where
t.date between '02/05/2015' and '03/05/2015' and
t2.date between '02/05. 2015' and '03/05/2015 ' and
t3.date between '02/05/ 2015 ' and '03/05/2015'
... using 2 variables... it takes 5 minutes. What type of data should be used in variables so that #1 will work as fast as #2?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
velnick, 2015-05-18
@Noob_001

I would venture to suggest that the problem is not in the data types, but in the execution plans and statistics of SQL Server.
And you don't pass random parameters to the store/function? Maybe Parameter Sniffing takes place here?
www.brentozar.com/archive/2013/06/the-elephant-and...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question