Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Execution Time When Using DateTime vs Char vs Constant
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01298827
Message ID:
01298842
Vues:
24
I would like to point out that there's a problem with the value of EndDate parmeter. The datime data type values are stored with accuracy of one three-hundredth of a second. It means that your query will miss records with time part between 23:59:59.003 - 23:59:59.997. The better way to handle it
set @BegDate	= convert(datetime,'03/04/2008')
set @EndDate	= convert(datetime,'03/06/2008')  -- +1 day
select sum(AmtDue) as AmtDue
	from invfl with (nolock) 	
	where InvDate >= @BegDate and InvDate < @EndDate
>I’ trying to get the sum of AmtDue between two dates. If I use a constant text date-range the Execution Time is 0. If use a variable, which I need to use; it takes 18 seconds. What is causing this?
>
>
>declare
>@BegDate		datetime,
>@EndDate		datetime,
>@BegDateChar		char(19),
>@EndDateChar		char(19)
>
>set @BegDate	= convert(datetime,'03/04/2008 00:00:00')
>set @EndDate	= convert(datetime,'03/05/2008 23:59:59')
>
>set @BegDateChar= convert(char,@BegDate)
>set @EndDateChar= convert(char,@EndDate)
>
>select
>@BegDate	as BegDate,
>@EndDate	as EndDate,
>@BegDateChar	as BegDateChar,
>@EndDateChar	as EndDateChar
>
>--Query-1 (Execution Time: 00:00:00)
>select sum(AmtDue) as AmtDue
>	from invfl with (nolock) 	
>	where invdate between '03/04/2008 00:00:00' and '03/05/2008 23:59:59'
>
>--Query-2 (Execution Time: 00:00:18)
>select sum(AmtDue) as AmtDue
>	from invfl with (nolock) 	
>	where InvDate between @BegDateChar	and @EndDateChar
>
>--Query-3 (Execution Time: 00:00:18)
>select sum(AmtDue) as AmtDue
>	from invfl with (nolock) 	
>	where InvDate between @BegDate		and @EndDate
>
>
>Can you please tell me what the correct syntax is?
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform