Avatar of gudii9
gudii9Flag for United States of America

asked on 

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
Microsoft SQL Server 2008Microsoft SQL ServerSSRSMicrosoft SQL Server 2005SSIS

Avatar of undefined
Last Comment
Aneesh
Avatar of Aneesh
Aneesh
Flag of Canada image

AND order.time_ins- timings.time_upd > DATEADD(MINUTE,-30, GETDATE() )
Avatar of gudii9
gudii9
Flag of United States of America image

ASKER

Msg 8117, Level 16, State 1, Line 1
Operand data type datetime2 is invalid for subtract operator.
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of gudii9
gudii9
Flag of United States of America image

ASKER

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
Avatar of Aneesh
Aneesh
Flag of Canada image

use the sql statement on my previous comment  or

 AND order.time_ins  > DATEADD(MINUTE,-30, timings.time_upd  )
Avatar of gudii9
gudii9
Flag of United States of America image

ASKER

Msg 174, Level 15, State 1, Line 2
The datediff function requires 3 argument(s).
Avatar of Aneesh
Aneesh
Flag of Canada image

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   )
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo