Date conversion to SQL server

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

pavanns
Participant
Posts: 27
Joined: Wed Sep 28, 2005 8:00 pm
Location: ca

Date conversion to SQL server

Post by pavanns »

Hi I have a VARCHAR field in the source that holds date in 1/11/2007 7:30:00 PM
I need to convert this into timestamp in the target can you please comment

Please note that the allowed format in SQL server is DATETIME
pavan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

And what format, precisely, does a DATETIME require?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
urshit_1983
Participant
Posts: 73
Joined: Wed Jun 28, 2006 3:27 pm
Location: NJ

Post by urshit_1983 »

you can use :-

TO_DATE(char[,fmt])

So as Ray mentioned in "fmt" use the format you need for eg :

TO_DATE('25-JUN-1952 10:55 A.M.','DD-MON-YYYY HH:MI A.M.')

In Transformer use Timestamp as SQL type for this field.
"Nobody is expert in Everything,
But Everybody is expert in Something."
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Look into ICONV/OCONV functions. You need to seperate the date and time part. Appy these functions seperately and concatenate them together.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
pavanns
Participant
Posts: 27
Joined: Wed Sep 28, 2005 8:00 pm
Location: ca

fmt specified for conversion

Post by pavanns »

i need it in the same format as input it is like 13/09/2007 11:00:00 AM

the input is from an xml and i tried even getting it from sequential file but both SQL types are varchar. i need the o/p on SQL SERVER also in the same format but as a DATETIME sql type. pls help

I tried doing to_date it is not woorking
pavan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If you need the format the same as input, declare it as VarChar throughout your job and do not apply any conversion at all.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
pavanns
Participant
Posts: 27
Joined: Wed Sep 28, 2005 8:00 pm
Location: ca

Post by pavanns »

i am getting an error cannot convert varchar to datetime null passed
pavan
shilpa79
Participant
Posts: 131
Joined: Thu Jan 20, 2005 5:59 pm
Location: Virginia

Post by shilpa79 »

I have the similar isuue:

I have to convert string to Timestamp
sample input date: " 1/10/2007 2:19:16 PM "

Thanks in advance
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Does'nt SQL Server take timestamp in YYYY-MM-DD for date and MTS format for time?
Does the following work for you guys

Code: Select all

OCONV(ICONV(Field(in.DATE, " ", 1), "D/DMY"),"D-YMD[4,2,2]):" ":OCONV(ICONV(Field(in.DATE," ",2), "MT"), "MTS")
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Reas it as Char and pass it as char. In SQL Server (ODBC) stage, use

Code: Select all

convert(char,Input.field,code)
.
Here the code corresponds to the given format. Which usually in the ranges like 100, 101, 102... for each format.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
shilpa79
Participant
Posts: 131
Joined: Thu Jan 20, 2005 5:59 pm
Location: Virginia

Post by shilpa79 »

DSguru2B wrote:Does'nt SQL Server take timestamp in YYYY-MM-DD for date and MTS format for time?
Does the following work for you guys

Code: Select all

OCONV(ICONV(Field(in.DATE, " ", 1), "D/DMY"),"D-YMD[4,2,2]):" ":OCONV(ICONV(Field(in.DATE," ",2), "MT"), "MTS")
in.DATE is a function or the Input date field column.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It is the input field column name, qualified by the name of the input link.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
shilpa79
Participant
Posts: 131
Joined: Thu Jan 20, 2005 5:59 pm
Location: Virginia

Post by shilpa79 »

ray.wurlod wrote:It is the input field column name, qualified by the name of the input link. ...
Do I need to change the sql type from Timestamp to varchar because its not loading anything if its Timestamp.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Try changing it. Also, since this is such a struggle, load it to a flat file, just a few records to see how it looks like. It should have two parts. The first is date in the format YYYY-MM-DD and second is time in the format HH:NN:SS. Both parts should have a single space in between them.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
shilpa79
Participant
Posts: 131
Joined: Thu Jan 20, 2005 5:59 pm
Location: Virginia

Post by shilpa79 »

shilpa79 wrote:
DSguru2B wrote:Does'nt SQL Server take timestamp in YYYY-MM-DD for date and MTS format for time?
Does the following work for you guys

Code: Select all

OCONV(ICONV(Field(in.DATE, " ", 1), "D/DMY"),"D-YMD[4,2,2]):" ":OCONV(ICONV(Field(in.DATE," ",2), "MT"), "MTS")
in.DATE is a function or the Input date field column.

I have given the same format still i am not able to load the date.

Oconv(Iconv(xo_dailysalestrans.TransTimestamp, " ", 1), "D/DMY"),"D/YMD[4,2,2]):" ":
Oconv(Iconv(xo_dailysalestrans.TransTimestamp," ",2), "MT"), "MTS")
Post Reply