data less than 30 minutes

i am trying below kind of query which should give count less than 30 minutes of difference of time. not able to execute below. How to modify to make it work

select count(order_nbr) from order INNER JOIN timings ON order.order_id=timings.order_id WHERE LEN(order_nbr) = 11 AND order_cd=02  AND order.time_ins- timings.time_upd <30 minutes
please advise
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase ConsultantCommented:
AND order.time_ins- timings.time_upd > DATEADD(MINUTE,-30, GETDATE() )
gudii9Author Commented:
Msg 8117, Level 16, State 1, Line 1
Operand data type datetime2 is invalid for subtract operator.
Aneesh RetnakaranDatabase ConsultantCommented:
sorry i missed the '-'

  select count(order_nbr) from [order] INNER JOIN timings ON [order].order_id=timings.order_id WHERE LEN(order_nbr) = 11 AND order_cd=02  

  AND DATEDIFF(MINUTE,  [order].time_ins,timings.time_upd) >30

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
5 Ways Acronis Skyrockets Your Data Protection

Risks to data security are risks to business continuity. Businesses need to know what these risks look like – and where they can turn for help.
Check our newest E-Book and learn how you can differentiate your data protection business with advanced cloud solutions Acronis delivers

gudii9Author Commented:
select count(order_nbr) from order INNER JOIN timings ON order.order_id=timings.order_id WHERE LEN(order_nbr) = 11 AND order_cd=02  AND order.time_ins- timings.time_upd > DATEADD(MINUTE,-30, GETDATE() )

Open in new window

i used like above
Aneesh RetnakaranDatabase ConsultantCommented:
use the sql statement on my previous comment  or

 AND order.time_ins  > DATEADD(MINUTE,-30, timings.time_upd  )
gudii9Author Commented:
Msg 174, Level 15, State 1, Line 2
The datediff function requires 3 argument(s).
Aneesh RetnakaranDatabase ConsultantCommented:
can you paste the exact query you are trying,  there are 3 arguments already in the datediff statement ,

datediff (MINUTE,  [order].time_ins,     timings.time_upd   )
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.