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 > The syntax of the string representation of a datetime value is incorrect

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-09-11, 23:54
nissan nissan is offline
Registered User
 
Join Date: May 2011
Posts: 5
The syntax of the string representation of a datetime value is incorrect

i have a query:
select ID from tb where date_from
NOT IN ('0001-01-01','')
AND date_to IN ('0001-01-01','');

The query should return all the ID with date_from that is not 0001-01-01 or ' ' and date_to that is '0001-01-01' or ' '.
I got an error saying,
The syntax of the string representation of a datetime value is incorrect.. SQLCODE=-180, SQLSTATE=22007
I am using db2 for windows,version v9.7. please help me fix the query thanks
Reply With Quote
  #2 (permalink)  
Old 05-10-11, 00:46
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
You may be trying to use '' as null. This works in Oracle, but doesn't work in DB2 unless maybe you have Oracle compatibility tuned on, or maybe they changed Db2 to allow it in 9.7.

Try

where date_from
NOT IN ('0001-01-01',null)
AND date_to IN ('0001-01-01',null);
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 05-10-11, 01:02
Artemis91 Artemis91 is offline
Registered User
 
Join Date: May 2011
Posts: 4
Lightbulb re:The syntax of the string representation of a datetime value is incorrect

you could try this instead:

AND (date_from <> '0001-01-01' or NOT(date_to IS NULL))
AND (date_to = '0001-01-01' or date_to IS NULL)

cheers
Reply With Quote
  #4 (permalink)  
Old 05-10-11, 01:07
nissan nissan is offline
Registered User
 
Join Date: May 2011
Posts: 5
The syntax of the string representation of a datetime value is incorrect Reply to Thr

thank you marcus, i have tried the null but it only returns nothing
Reply With Quote
  #5 (permalink)  
Old 05-10-11, 06:37
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
Quote:
AND (date_from <> '0001-01-01' or NOT(date_to IS NULL))
AND (date_to = '0001-01-01' or date_to IS NULL)
"or" should be "AND", like this...
AND (date_from <> '0001-01-01' AND NOT(date_from IS NULL))
AND (date_to = '0001-01-01' or date_to IS NULL)

If "date_from <> '0001-01-01'" is true, it implies date_from IS NOT NULL.
(If date_from is null, "date_from <> '0001-01-01'" is UNKNOWN.)
So, this will be enough.
AND date_from <> '0001-01-01'
AND (date_to = '0001-01-01' or date_to IS NULL)
Reply With Quote
  #6 (permalink)  
Old 05-10-11, 22:21
nissan nissan is offline
Registered User
 
Join Date: May 2011
Posts: 5
i got it. thanks artemis and tonkuma..
Reply With Quote
Reply

Tags
datetime, representation, string, syntax

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