ssis derived column format - sql

in ssis I'm loading a data file that has a date field formatted as 11171977 into a table with a data type of varchar(8).
i can load this into the table fine; however, I need to reformat the data as yyyymmdd so it is 19771117.
my first attempt was to load as is then query with the following convert:
convert(varchar(8),convert(date,substring (BirthDate,1,2)+'/'+substring (BirthDate,3,2)+'/'+substring (BirthDate,5,4),101), 112)
that gives me yyyymmdd = 19771117.
however, I tried to do a derived column with no luck as it didn't like my expression.
how do i do this in an expression in the derived column?

Try something like this:
right(BirthDate,4)+left(BirthDate,4)

Related

Getting Error : "Invalid date: [19/8/2013]. The row will be skipped in informatica

We have a source as a flat file which consists of a date column in format 19/08/2013.
We have a target in oracle table which consists of a date column in format 11-AUG-13.
When we are trying to pass the source column value in target using expression TO_DATE AND
TO_CHAR like
**source column is A ---> Source column
v1=TO_CHAR(A)
O1(output column)=TO_DATE(V1,'DD-MON-YY') we are getting the below error.
Invalid date: [19/8/2013]. The row will be skipped.**
Can anyone please help where I'm going wrong.
Thank you
You need to convert the str to date properly and then infa will load them.
Change the mapping like this -
Change data type in source to a string. read data as string.
Then use your expressions but change the to_date function like below.
v1(var column, data type string)=A
O1(output column, data type date)=IIF(IS_DATE(V1,'DD/MM/YYYY'), TO_DATE(V1,DD/MM/YYYY'),null)
IS_DATE - will check if the data is a date or not, if yes then only it will try to convert to a proper date else put null.
3. Then connect O1 column to a date type in oracle target.
This will make sure all data are loaded and none skipped.

Convert varchar value to datetime in SQL Server 2012

In my import table I have the following column defined:
LFZ_begin VARCHAR(50) NULL
Now when I try to define the column in a view as DATETIME and call the view in SSMS, I get the following error message:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
In my view the column is defined as follows:
CONVERT(VARCHAR(50), CONVERT(DATETIME, LFZ_begin, 120)) AS LFZ_begin,
I need to expect the result value like that: 2020-09-04 00:00:0000
Does anyone have an idea for this issue?
You should fix your data model and never store date/time values as strings. In the meantime you can fix the view using try_ functions:
TRY_CONVERT(VARCHAR(50), TRY_CONVERT(DATETIME, LFZ_begin, 120)) AS LFZ_begin,
Note: This will eliminate the error on invalid formatted columns. Whether it ever returns a valid value depends on the data -- and you have shown no sample data so there is no way to suggest a solution to whatever the underlying problem is.

How do I convert a string of format dd/mm/yy into datetime in SQL Server 2008?

I have table named PTBV with two columns: Dateptbv varchar(50) and [Column 1] varchar(50).
I'm trying to use the CONVERT() function to get actual datetime values from the string data stored in the Dateptbv column.
Here are examples of the data in that column:
"10/01/13"
"11/01/13"
"14/01/13"
"15/01/13"
"16/01/13"
"17/01/13"
"18/01/13"
"21/01/13"
"22/01/13"
"24/01/13"
"25/01/13"
"28/01/13"
"29/01/13"
"30/01/13"
"01/02/13"
"04/02/13"
Note that the quotation marks in this sample are part of the data and are stored in the column. Otherwise, data is stored in dd/mm/yy format.
Unfortunately, every date style I've tried has resulted in an error message. How can I convert this data into DateTime values?
If I understand your picture correctly, your column Dateptbv is VARCHAR(50) and stores the date as yy/mm/dd wrapped in " characters. First of all: Change this, if ever possible!. Try to store values in appropriately typed columns!
Try
SELECT CONVERT(DATE,SUBSTRING(Dateptbv,2,8)),3) --3 for dd/mm/yy
Read this link to find more details about the abilities of CONVERT.
Try the below script
SELECT CAST(SUBSTRING(Dateptbv,2,8) AS DATE)
FROM PTBV

SSIS: What are rules to import date fields from text files to SQL table

I have created a package in |SSIS 2012. The package basically connect to a text files in a predefined location and load data from the text files to the SQL database table. I have one DOB field which is DATE TYPE in the destination SQL table and it was returning error: conversion failed and date out-of-range.
I did not have any luck converting DOB column using the CAST or CONVERT funtion:
CONVERT(date, DOB, 103)
What am I doing wrong?
You should use CAST() or CONVERT() functions, when you want convert varchar value to datetime
https://msdn.microsoft.com/ru-ru/library/ms187928.aspx
I had some bad data in my input files for the DOB column. For example, DOB: 100-01-01, 29999-05-24; I tried to convert these dates using CONVERT function and it was returning error.
So, I was just selecting records only with valid DOB dates using the query as below and after that I could convert the DOB without any error in this case:
SELECT * FROM MyTableTest WHERE ISDATE(dob) <> 1

What format is this date and how can I convert it to a regular datetime?

Amazon for sellers provides order reports. I'm trying to import one of these order reports into a Sql Server database:
Their date fields look like this:
2014-04-30T12:17:28-07:00
2014-04-30T12:24:43-07:00
2014-04-30T12:25:34-07:00
2014-04-30T12:46:02-07:00
2014-07-27T13:10:02-07:00
2014-07-27T13:12:09-07:00
2014-07-27T13:20:42-07:00
2014-07-27T13:23:25-07:00
2014-07-27T13:29:10-07:00
2014-07-27T13:36:16-07:00
2014-07-27T13:51:41-07:00
I cannot figure out which data type to assign this date.
How do I convert this field to be a regular datetime? The solution could be SQL or SSIS or a combination.
Try this.....
SQL Server
SELECT CONVERT(DATETIME,
CONVERT(DATETIME2, '2014-04-30T12:17:28-07:00')
)
RESULT: 2014-04-30 12:17:28.000 --<-- SQL SERVER DATETIME
SSIS
Convert your input column to SSIS Data type DT_DBTIMESTAMP2
Add a derived column task and use the following expression
(DT_DBTIMESTAMP)Input_Column_Name
essentially you are doing the same thing but result will be the same.