If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > SQL0401N The data types of the operands for the operation "BETWEEN" are not compatib

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-04, 14:04
manth manth is offline
Registered User
 
Join Date: Mar 2004
Posts: 54
SQL0401N The data types of the operands for the operation "BETWEEN" are not compatib

Hi,

I used the following command for DB2 v7

SELECT count(MSGTYPE) from db2admin.MQMD where TSTAMP BETWEEN date('2004-01-01') and date('2004-01-10')

it says
SQL0401N The data types of the operands for the operation "BETWEEN" are not compatible. SQLSTATE=42818

I appreciate ur help!

Thanks
Reply With Quote
  #2 (permalink)  
Old 03-29-04, 14:10
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Is TSTAMP a TIMESTAMP?

You can't use a DATE range for a TIMESTAMP column.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 03-29-04, 14:13
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally posted by J Petruk
Is TSTAMP a TIMESTAMP?

You can't use a DATE range for a TIMESTAMP column.
I should give a suggestion too...

BETWEEN '2004-01-01-00.00.00.000000' AND '2004-01-11-00.00.00.000000'

(Note 01-11 instead of 01-10... inclusive)
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #4 (permalink)  
Old 03-29-04, 14:23
manth manth is offline
Registered User
 
Join Date: Mar 2004
Posts: 54
as Jonathan Petruk said it's working fine.

But it's returning 0 count though it has records in the table between those 2 days.

Let me explain
I have a table called MQMD
I have TSTAMP, MSGID, MSGTYPE as columns.
i have 3 unique MSGTYPEs
they are 1, 8, 9

I need result like this

MessageType count
--------------- -------
1 100
8 65
9 17

Now please correct my query.

Thanks
Reply With Quote
  #5 (permalink)  
Old 03-29-04, 14:31
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
You need to use GROUP BY.

SELECT MSGTYPE, COUNT(*)
FROM MQMD
GROUP BY MSGTYPE;

I charge by the hour, the invoice is in the mail...
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #6 (permalink)  
Old 03-29-04, 14:36
manth manth is offline
Registered User
 
Join Date: Mar 2004
Posts: 54
Thumbs up

Petruk

it's excelent!!
it's working

Thanks
Reply With Quote
  #7 (permalink)  
Old 03-29-04, 14:38
manth manth is offline
Registered User
 
Join Date: Mar 2004
Posts: 54
By the by i forgot ask one thing
I want show this result for the given 2 timestamps

how do we do that?
Reply With Quote
  #8 (permalink)  
Old 03-29-04, 14:43
manth manth is offline
Registered User
 
Join Date: Mar 2004
Posts: 54
o.k. i could figured it out

db2 => SELECT MSGTYPE, COUNT(*) count FROM db2admin.MQMD WHERE TSTAMP BETWEEN '2004-03-28-00.00.00' AND '2004-03-29-00.00.00' GROUP BY MSGTYPE

MSGTYPE COUNT
----------- -----------
1 1505
2 1684

2 record(s) selected.

Thanks
Reply With Quote
  #9 (permalink)  
Old 03-29-04, 14:43
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally posted by manth
By the by i forgot ask one thing
I want show this result for the given 2 timestamps

how do we do that?
Add the WHERE clause back in before the GROUP BY.

And pick up a book on SQL.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On