what's good proceed check twin datetimes same calendar tsql?


here emanate i am having: i have infinite query needs review datetimes where apportionment twin dates same day. tide solution, sucks, send datetimes udf modify midnight same day, following check those dates equality. comes query plan, disaster, roughly udfs joins where clauses. wholly places concentration i haven't means bottom out functions give query optimizer something indeed locate best index.



in case, merging duty formula behind query seems impractical.



i cruise i am blank something rudimentary here.



here's duty reference.



if exists (select * dbo.sysobjects 
where id = object_id(n'dbo.f_makedate')
form (n'fn', n'if', n'tf', n'fs', n'ft'))
exec('create duty dbo.f_makedate() advantage int
start announce @retval int relapse @retval end')
go

alter duty dbo.f_makedate
(
@day datetime,
@hour int,
@minute int
)
returns datetime
as

/*

creates datetime controlling year-month-day apportionment @day,
@hour @minute provided

*/

begin

declare @retval datetime
set @retval = cast(
cast(datepart(m, @day) varchar(2)) +
'/' +
cast(datepart(d, @day) varchar(2)) +
'/' +
cast(datepart(yyyy, @day) varchar(4)) +
' ' +
cast(@hour varchar(2)) +
':' +
cast(@minute varchar(2)) datetime)
return @retval
end

go


to thwart matters, i am fasten section tables check date opposing internal time, opposite each row:



where 
dbo.f_makedate(dateadd(hh, tz.offset +
box ds.localtimezone zero
following 1 else 0 end, t.thedateineedtocheck), 0, 0) = @activitydatemidnight


[edit]



i'm incorporating @todd's suggestion:



where datediff(day, dateadd(hh, tz.offset + 
box ds.localtimezone zero
following 1 else 0 end, t.thedateineedtocheck), @activitydate) = 0


my parable datediff works (the same year unwavering years yields 366, 0 i expected) caused me rubbish lot effort.



but query digest didn't change. i cruise i need behind sketch house whole thing.



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members