Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 29th, 2007, 07:47 AM
gog gog is offline
Registered User
 
Join Date: Apr 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date From DB2

Hi
i'm trying to run this:

select *
from openquery(DB2_SERVER,
'SELECT *
FROM DB2USER.DB2TABLE
where (TableDateTime between CURRENT_DATE-1 DAYS AND CURRENT_DATE )')

i get an error :
The data types of the operands for the operation "BETWEEN" are not compatible

no operation works i know that CURRENT_TIMESTAMP is working .

HELP !!!!!!!!
 
Old April 29th, 2007, 01:28 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please look at the query.
What is the word DAYS doing there?


 
Old April 30th, 2007, 12:12 AM
gog gog is offline
Registered User
 
Join Date: Apr 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

tryed :between CURRENT_DATE-1 AND CURRENT_DATE
not working.
the data type of : TableDateTime is smalldatetime.



 
Old April 30th, 2007, 01:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

What does it mean "not working"? Did you get any error, if so how about posting it here? Why dont you try using DATEDIFF() for date calculations rather than doing a straight "- 1" there ?

_________________________
- Vijay G
Strive for Perfection
 
Old April 30th, 2007, 03:02 AM
gog gog is offline
Registered User
 
Join Date: Apr 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok
i'm talking about DB2 working with sqlserver2000 :
the problem:i'm trying to compair-
smalldatetime with CURRENT_DATE on DB2 working with sqlserver.
TableDateTime is smalldatetime like : 29/04/2007 15:12:21.0000 .

what i'm trying to do is to take yesterday so i ran this first :

select *
from openquery(DB2_SERVER,
'SELECT *
FROM DB2USER.DB2TABLE
where (TableDateTime CURRENT_TIMESTAMP -1 DAYS-5 HOURS AND CURRENT_TIMESTAMP )')

and its working well but i have more/less then one day and i need only one day yesterday .
DATEDIFF() ? no function on DB2(openquery) .
i can solve it with CURRENT_TIMESTAMP then convert to date and delete the none yestrday ones .

select *
from openquery(DB2_SERVER,
'SELECT *
FROM DB2USER.DB2TABLE
where (TableDateTime between CURRENT_DATE-1 DAYS AND CURRENT_DATE )')
error :
The data types of the operands for the operation "BETWEEN" are not compatible.


select *
from openquery(DB2_SERVER,
'SELECT *
FROM DB2USER.DB2TABLE
where (TableDateTime between CURRENT_DATE-1 AND CURRENT_DATE )')

error :
An expression with a datetime value or a labeled duration is not valid .



 
Old April 30th, 2007, 03:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:The data types of the operands for the operation "BETWEEN" are not compatible.
I dont have DB2 environment to see how that works. Moreover I am not sure what it returns when CURRENT_DATE-1 is executed there. From the Error that you posted, all I can think of is that the CURRENT_DATE-1 OR CURRENT_DATE seems to be resulting different types of values which is not conforming with that of the the TableDateTime. Try and check if that is a possiblity for this error.
It is better to do the following from your OPENQUERY() and see if all the 3 return values of similar datatype.
SELECT CURRENT_TIMESTAMP -1 DAYS-0 HOURS, CURRENT_TIMESTAMP -1 DAYS, CURRENT_TIMESTAMP

I see "BETWEEN" missing in the below code...
(TableDateTime CURRENT_TIMESTAMP -1 DAYS-5 HOURS AND CURRENT_TIMESTAMP )
But the same being used in the other one. Is that you missed it by mistake? When you say this one works...then see if this helps...
CURRENT_TIMESTAMP -1 DAYS-0 HOURS

Cheers.

_________________________
- Vijay G
Strive for Perfection
 
Old April 30th, 2007, 06:13 AM
gog gog is offline
Registered User
 
Join Date: Apr 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank's
1.CURRENT_TIMESTAMP -1 DAYS-0 HOURS ==CURRENT_TIMESTAMP -1 DAYS.
it's date-1 + now time .0 Hours .
2.my mistake .
3.on sqlserver the data type is the same datetime.
also CURRENT_DATE and TableDateTime are datetime.it's DB2 that returns the error.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Db2 Biju6 SQL Server 2000 0 September 23rd, 2007 09:53 PM
Trigger in DB2 htyeoh SQL Language 0 March 13th, 2007 09:09 PM
Websphere DB2 vijayakumaroa J2EE 0 November 15th, 2005 01:08 PM
Help w/ DB2 Triggers rrr24 Access 1 September 21st, 2004 01:13 AM
asp and DB2 beta611 Classic ASP Basics 0 August 20th, 2003 09:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.