Link to home
Start Free TrialLog in
Avatar of sitijaafar
sitijaafarFlag for Malaysia

asked on

Problem with select statement that contains datetime type

Hi experts,
How to select the data where the condition 'yyyy-mm-%' and 'yyyy-%'

select count=count(*) from audit_trail where access_time like '2009-11-%'

and

select count=count(*) from audit_trail where access_time like '2009-%'

This statement fine in mysql but not ms sql.

The data is like below
user               access_time
-------              -----------------------
zazimi      2009-11-26 15:19:51.717      
qaisara      2009-11-26 15:20:24.747      
Avatar of amer1
amer1
Flag of Saudi Arabia image

Try:
select count=count(*) from audit_trail where year(access_time) =2009 and month(access_time) =11
select count=count(*) from audit_trail where year(access_time) =2009
ASKER CERTIFIED SOLUTION
Avatar of himanshut
himanshut
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sitijaafar

ASKER

(^_^)