Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2003, 09:06 AM
vjdupps vjdupps is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 16 vjdupps User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old November 6th, 2003, 12:11 PM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,717 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 18 h 28 m 55 sec
Reputation Power: 986
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/

Reply With Quote
  #3  
Old November 7th, 2003, 08:30 AM
vjdupps vjdupps is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 16 vjdupps User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks a lot.

The code worked just fine.

VJ

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > SQL Query error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway