473,320 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

CHAR to DATE conversion

Hello,

I imported the file with date values .... since I dont know any possibility how to import value like '20080429' as date directly I imported the column as char and now I would like to setup trigger or counted column which will convert the char to date for me.

I wrote the trigger:
Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER SCANTIME
  2. AFTER INSERT ON xxx.ASSET_REPORT
  3. FOR EACH ROW
  4. UPDATE xxx.ASSET_REPORT
  5. BEGIN
  6. SET SCAN_DATE =
  7. CASE
  8. WHEN SCANTIME_DATE IS NULL
  9. THEN 'MISSING'
  10. WHEN SCANTIME_DATE IS NOT NULL
  11. THEN TO_DATE (SCANTIME_DATE,'YYYYMMDD')
  12. END;
BUT - I am getting error :
During SQL processing it returned:
Expand|Select|Wrap|Line Numbers
  1. SQL0171N  The data type, length or value of argument "2" of routine
  2. "SYSIBM.TO_DATE" is incorrect.  LINE NUMBER=2.  SQLSTATE=42815
... since I wrote it following the syntax on IBM pages I dont have any idea what can be wrong there ...

Thanks a lot for help.
Apr 29 '08 #1
1 2902
docdiesel
297 Expert 100+
Hi,

please use code tags when publishing code in your posts for better readability. As for your date conversion problem:
  1. Load your data to a secondary/temporary table.
  2. Create a view on that table, which converts the char(8) field (e.g. named c8date) to a date value.
  3. Load your destination table via cursor from the view.

The conversion part of the view should look like this:
Expand|Select|Wrap|Line Numbers
  1. Create View
  2.   show_char8_as_date
  3. AS
  4.   select
  5.     date(
  6.     substr(c8date,1,4)
  7.     || '-'
  8.     || substr(c8date,5,2)
  9.     || '-'
  10.     || substr(c8date,7,2)  ) as realdate
  11.   from ...
Regards,

Bernd
Apr 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Connie Sawyer | last post by:
I am trying to run the following query: ALTER TABLE dnb_profile ALTER COLUMN datetime and I keep getting the following error: Server: Msg 242, Level 16, State 3, Line 1 The conversion of...
30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
1
by: Amir | last post by:
Hi all, I have a table called PTRANS with few columns (see create script below). I have created a view on top that this table VwTransaction (See below) I can now run this query without a...
2
by: Peter Nilsson | last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think about what the conversion of a char to unsigned char would mean, and whether it was sensible to actually do so. And pete has...
1
by: lovecreatesbeauty | last post by:
There is a warning/(error? I remember it is an error for line 10 on some compilers before. At least on g++, it is an error.) for line 10. I first read a similar example from `Expert C Programming...
3
by: Kevin Frey | last post by:
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the new C++/CLI syntax rather than /clr:oldSyntax. Much of our managed code is concerned with interfacing to native C++...
0
by: coolvivek33 | last post by:
hi i am facing a strange problem i am trying to build report using sql server 2005 and microsoft visual studio2005 now it is in requirement that i should seperate date from time.I have done that...
1
by: Roobmeister | last post by:
I am trying to return either a date in MMDDYYYY format, or a blank fixed width of 8 as part of a giant concatenation. For some reason, I am stuck on this point: ...
0
by: maheshmohta | last post by:
Background Often while remodeling legacy application, one of the important tasks for the architects is to have an optimum usage of storage capabilities of database. Most of the legacy applications...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.