SQLTeam.com | Weblogs | Forums

Query Problem

Hello,
how to get data from where Time clause in SQL Query

My query is like this

             select  *  from  [order] 
             where CreatedOnUtc  =  '2014-07-21 07:12:39.550'

Not Sure What you Mean

Are you saying you just want

Where Time-CreatedOn = Time-FromVariable

what you have is correct. but it will give you records where the time stamp is exactly 07:12:39.550 on date 2014-07-21

Did you want something else?

1 Like

Hello. If you need to compare date parts of datetime values (ignoring time), this query may help:

select  *  from  [order] 
             where convert(date,CreatedOnUtc) = '2014-07-21'

The use of any function on a column will make it non sargable. (ie Any index on the column will not be used.)

It would be better practise to write:

SELECT *
FROM [order]
WHERE CreatedOnUtc >= '20140721'
	AND CreatedOnUtc < '20140722';
1 Like