If you want a single month/year pair the following query will work:
select *
from Patient_Ref_Master
where Cast( '20130801' as Date ) <= Creation_Date and Creation_Date < Cast( '20130901' as Date )
It has the advantage that the query can use an index since it does not need to perform a calculation on each row.
It is often helpful to calculate the limits prior to the query, e.g. the current month:
declare @Start as Date = DateAdd( month, DateDiff( month, 0, GetDate() ), 0 );
declare @End as Date = DateAdd( month, 1, @Start );
select *
from Patient_Ref_Master
where @Start <= Creation_Date and Creation_Date < @End
EDIT: If the use of comparison operators thrown together willy-nilly with boolean operators is overwhelming, I offer the following simplification:
declare @Patient_Ref_Master as Table ( Id Int Identity, Creation_Date Date );
insert into @Patient_Ref_Master ( Creation_Date ) values
( '20130731' ), ( '20130801' ), ( '20130815' ), ( '20130831' ), ( '20130901' );
select * from @Patient_Ref_Master;
declare @Start as Date = DateAdd( month, DateDiff( month, 0, Cast( '20130829' as Date ) ), 0 );
declare @End as Date = DateAdd( month, 1, @Start );
-- Incomprehensible WHERE clause:
select *
from @Patient_Ref_Master
where @Start <= Creation_Date and Creation_Date < @End;
-- Simplified AB version:
with
JustRight as (
select *
from @Patient_Ref_Master
where Creation_Date in ( @Start ) ),
NotTooLate as (
select *
from @Patient_Ref_Master
where Sign( DateDiff( day, @End, Creation_Date ) ) in ( -1 ) ),
NotTooSoon as (
select *
from @Patient_Ref_Master
-- NB: Do NOT include zero in the set of matches. That would be too easy.
where Sign( DateDiff( day, Creation_Date, @Start ) ) in ( -1 ) ),
TheResult as (
select *
from JustRight
union
select *
from NotTooLate
intersect
select *
from NotTooSoon )
select * from TheResult;
No, IN
is not listed in the documentation as a comparison operator.