SQL command for "like" clause for datetime type.

Posted by Anishabathija under Sql Server on 11/14/2012 | Points: 10 | Views : 9749 | Status : [Member] | Replies : 2
hey ,

Like how we have a sql query for like clause

Select * from Students where firstname like "A%" and lastname = "bathija"

can we have something similar for the datatime type cause the above seems to be working only for string type and not datetime type.

Please help!!
thanks




Responses

Posted by: Funda on: 11/14/2012 [Member] Starter | Points: 25

Up
0
Down
DATEPART
select * from record 

where (DATEPART(yy, register_date) = 2009
AND DATEPART(mm, register_date) = 10
AND DATEPART(dd, register_date) = 10)


CONVERT
SELECT (list of fields) FROM YourTable
WHERE CONVERT(VARCHAR(25), register_date, 126) LIKE '2009-10-10%'

select *
from record
where CONVERT(VARCHAR(10),register_date,120) = '2009-10-10'
VARIABLE
declare @start datetime, @end datetime

select @start = '2009-10-10', @end = '2009-11-10'
select * from record where register_date >= @start
and register_date < @end


BETWEEN operator.
SELECT BusinessEntityID

, RateChangeDate
FROM HumanResources.EmployeePayHistory
WHERE RateChangeDate BETWEEN '20011212' AND '20020105'

~~~~~~~~~~~~~~
Select * From ModelRequests Where RequestDateTime >= '2000-09-21' and RequestDateTime < '2000-09-22'


Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saratvaddilli on: 11/14/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
good explanation funda

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response