|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL Query error
Hi all,
I have problem with the below query. I am using SQL server 2000 DB. I tried the query in the query analyzer and it gave me the following error. **** Invalid operator for data type. Operator equals multiply, type equals datetime. ****** The below is my query: SELECT [OR Record].[Date of Surgery], 24*([Anesthesia stop time]-[Anesthesia start time]) AS Expr1 FROM [OR Record] GROUP BY [OR Record].[Date of Surgery],24*([Anesthesia stop time]-[Anesthesia start time]) HAVING ((([OR Record].[Date of Surgery]) Between '10/01/2003' And '10/31/2003')); The columns [Anesthesia stop time] and [Anesthesia start time] are in date-time format. Thanks in advance. VJ |
|
#2
|
||||
|
||||
|
the problem is that by default, sql server returns a date when you subtract two dates
you need the DATEDIFF() function why are you grouping? your date range condition should be moved to the WHERE clause in any case Code:
SELECT [OR Record].[Date of Surgery]
, 24 * datediff( HH -- assuming you want hours
, [Anesthesia stop time]
, [Anesthesia start time] ) AS Expr1
FROM [OR Record]
WHERE [OR Record].[Date of Surgery])
Between '2003-10-001' And '2003-10-31'
GROUP
BY [OR Record].[Date of Surgery]
rudy http://r937.com/ |
|
#3
|
|||
|
|||
|
Thanks a lot.
The code worked just fine. VJ |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > SQL Query error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|