Help

hey guys im having a problem with my query
select idmedicament,dateExpiration from stock where (SELECT DATEDIFF(day,dateExpiration,getdate()) FROM stock )>=21

but bring me this error below
Msg 512, Level 16, State 1, Line 13
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

please help me because is an academic project

1 Like

select idmedicament,dateExpiration from stock where DATEDIFF(day,dateExpiration,getdate())>=21

thx guys it working and it helps me alot

To increase performance, you could do the following (assuming dateExpiration is date type field):

select idmedicament
      ,dateExpiration
  from stock
 where dateExpiration>=dateadd(day,-21,getdate())

If dateExpiration is datetime type field, do this:

select idmedicament
      ,dateExpiration
  from stock
 where dateExpiration>=dateadd(day,datediff(day,0,getdate())-21,0)