A forma mais simplificada para fazer isso é simplesmente comparando uma data com a outra where data = @Data
, veja os exemplos abaixo.
declare @Data datetime = cast('01/01/2016 12:50:00.000' as datetime)
declare @paciente table
(
id int,
data datetime
)
insert into @paciente values
(1, GETDATE()),
(2, cast('01/01/2016 12:50:10.001' as datetime)),
(3, cast('01/02/2016 12:50:00.000' as datetime)),
(4, cast('01/01/2016 12:40:00.000' as datetime)),
(5, cast('01/01/2016 12:50:00.000' as datetime))
select * from @paciente
where data = @Data
-- ou
select * from @paciente
where cast(data as date) = cast(@Data as date)
and cast(data as time) = cast(@Data as time)
-- ou
select * , convert(varchar, data, 108) from @paciente
where year(data) = year(@data)
and month(data) = month(@data)
and day(data) = day(@data)
and convert(varchar, data, 108) = convert(varchar, @data, 108)
Veja algumas dicas sobre datetime.
Referencia 1
Referencia 2
Referencia 3
Referencia 4