In SQL, from the start and end dates to integer dates and use> = @BeginDate and very specifically <@ end date. The rounding process is not very elegant, I'm afraid
eg.
SELECT @BeginDate = DATEADD(Day, DATEDIFF(Day, 0, @BeginDate), 0), @EndDAte = DATEADD(Day, DATEDIFF(Day, 0, @EndDAte) + 1, 0) select * from weblogs.dbo.vwlogs where Log_time >= @BeginDate and Log_time < @EndDAte and (@UserName Is null OR client_user=@UserName ) order by Log_time desc
Please note that I adopted "@UserName Is null", as there is some evidence that this test will easily pass / fail and will ignore the second more intensive CPU test (client_user = @UserName) if the first test is TRUE (maybe , TommyRot, of course ...)
Also, for best performance, you should explicitly specify all the columns you need and not use "SELECT *" (but this could only be for the purposes of this question).
source share