In SSIS package I am using a flat file source with a date column and some of the dates are with 0 value. The date column format is YYYYMMDD and I am converting this to YYYY-MM-DD format in derived column. If the date exists, the date is converting, but getting error for the date if it has 0. source file date datatype is DT_STR and destination SQL table field datatype is smalldatetime.
Please suggest logic for allowing the zero value in the derived column. I am using below logic.
[Date] == 0 ? NULL(DT_DATE) : (DT_DATE)(SUBSTRING([Date],1,4) + "-" + SUBSTRING([Date],5,2) + "-" + RIGHT([Date],2))
Can you try to replace (DT_Date) with (DT_DBDATE) ?
[Date] == 0 ? NULL(DT_DBDATE) : ...
You are mixing data types. [Date] is a string and can't be compared to 0.
Try this:
[Date] == "0" ? NULL(DT_DATE) : (DT_DATE) (SUBSTRING([Date],1,4) + "-" + SUBSTRING([Date],5,2) + "-" + RIGHT([Date],2))
Related
I have data in a CYYMMDD date format which I need to convert into YYYY-MM-DD in SSIS Package.
How to achieve this?
Any help will be appreciable.
Suppose your CYYMMDD column is called cdate and let's call the transformed date ydate then you may need a Derived Column transformation with this expression:
LEFT(cdate,1) == "0"
? "19" + SUBSTRING(cdate,2,2) + "-" + SUBSTRING(cdate,4,2) + "-" + RIGHT(cdate,2)
: "20" + SUBSTRING(cdate,2,2) + "-" + SUBSTRING(cdate,4,2) + "-" + RIGHT(cdate,2)
result:
How can I convert SQL smalldatetime or datetime like this:
select cast(getdate() as smalldatetime)
To JSON format like this:
/Date(1576278000000+0100)/
I just find this post in another issue like you got it.
Maybe it would work for you
"render": function ( data, type, row ) {
var fecha = new Date(parseInt(data.match(/\d+/)[0]));
return fecha.getMonth() + 1 + '/' + fecha.getDate() + '/' + fecha.getFullYear();;
},
"targets": 0
and this is the link that I found
https://es.stackoverflow.com/questions/125686/convertir-fecha-en-javascript
I have a derived column data flow component and I need to insert data to a table.
I am having a problem converting the following string to DATETIME "20130822 14:52:53", how would I go about this?
Please assist
Derived column code:
(DT_DBTIMESTAMP)(SUBSTRING(LTRIM(string),1,4) + "-" + SUBSTRING(LTRIM(string),5,2) + "-" + SUBSTRING(LTRIM(string),7,2) + SUBSTRING(LTRIM(string),9,LEN(LTRIM(string)) - 7))
Result:
string date
20130822 14:52:53 2013-08-22 14:52:53.000
In ssis package I have String type variable V2 inside expression property i'm writing following sql query
"select * from mytable where date = " + #[System::StartTime]
But it is giving me an error :
The data types "DT_WSTR" and "DT_DATE" are incompatible for binary operator "+". The operand types could not be implicitly cast into compatible types for the operation. To perform this operation, one or both operands need to be explicitly cast with a cast operator.
Attempt to set the result type of binary operation ""select * from table where date = " + #[System::StartTime]" failed with error code 0xC0047080.
Even I have also tried with (DT_WSTR) #[System::StartTime]
still no luck any advice ?
You need to change data type of both StartTime variable and [date] field from the query to string.
Try this:
"select * from mytable where convert( varchar(10), [date], 120) = '" + SUBSTRING((DT_WSTR,50)#[System::StartTime],1, 10) + "'"
Which should return a proper query:
select * from mytable where convert( varchar(10), [date], 120) = '2013-05-22'
convert() will give you string like "2013-05-22". In my system (DT_WSTR) cast on #[System::StartTime] is returning string "2013-05-22 16:14:43", but if you have other settings, you'd have to construct the string from dateparts, if your default result would be for example "05/22/2013 16:14:43" due to other regional setting.
What is the verion of sql server you are using? and [date] field type exactly?
i have this Ttime as nvarchar(10): "09:52:48" and i have TmpTime as date
and i try to convert like this: "UPDATE MEN SET TmpTime = CONVERT(DATETIME, Ttime ,108 )"
and i get in TmpTime this: "1900-01-01"
why ?
thank's in advance
If you also have a date field, you should to concatenate them before to cast:
CREATE TABLE #Sample ( DateField varchar(10), TimeField varchar(10) );
GO
INSERT INTO #Sample VALUES ('2009-01-24', '09:52:48');
SELECT CONVERT(DATETIME, DateField + ' ' + TimeField) as Converted FROM #Sample
And you'll get:
Converted
-----------------------
2009-01-24 09:52:48.000
You have a column defined as "date" and then you are sending only a time value into it
The date portion defaults to zero which is 01 January 1900 in SQL (in the CONVERT). Then the time is ignored for a date column.
What do you expect to happen?
(The same would happen whether or not you use CONVERT or not because the column is "date")