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))
I am inserting data into MYSQL from node.js using node-mysql. I can insert data correctly via a MYSQL stored procedure call in Node except that my dates are always inserting as 0000-00-00 00:00:00
The date strings I am trying to insert are in the format: dd/mm/yyyy hh:mm:ss
I'm assuming I need to correctly format my dates in Node.js to insert?
connection.query('CALL sp_InsertUpdateOffer(' + NetworkID + ',"' + data["Promotion ID"] + '",' + data["Advertiser ID"] + ',"' + DataCleanUp(data.Description) + '",null,"' + DataCleanUp(data.Categories) + '","' + DataCleanUp(data.Code) + '","' + DataCleanUp(data.Terms.substring(0, 1000)) + '","' + data.Starts + '","' + data.Ends + '","' + DataCleanUp(data["Deeplink Tracking"]) + '","' + DataCleanUp(data.Deeplink) + '","' + DataCleanUp(data.Advertiser) + '")', function (err, rows, fields) {
});
Thanks
you can re arrange your date format to 0000-00-00 00:00:00
If your date is in this format dd/mm/yyyy hh:mm:ss
do this to re arrange your date.
$date_select = "12/12/2016";
$newdate = explode("/",$date_select);
$final_date = $newdate[2]."-".$newdate[1]."-".$newdate[0];
now pass the $final_date to your insert query.
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
I want to convert a string like "2152012 101946" using a derived column in SSIS.
The output should be like "21/05/2012 10:19:46" to fit into a [DateTime] SQL Server 2008 field
Thanks!
You should think about enriching your date time data . You need to have a proper format like
YYYYMMDD HH:MM::SS
or something similar to it . You just can't have
YYYYMDD HH:MM:SS
If you have your data in the correct format DDMMYYY HH:MM:SS then you can use the below expression in derived column
LEN(column) == 0 ? NULL(DT_DBTIMESTAMP) :
(DT_DBTIMESTAMP)(substring(column,1,2) + "-" + substring(column,3,2) + "-" +
substring(column,5,4) + " " + substring(column,10,2) + ":" substring(column,12,2)+ ":"
+ substring(column,14,2))
DT_DBTIMESTAMP data types must be in the following format for proper conversion:
YYYY-MM-DD HH:MM:SS
Using the date & time "2012-07-30 02:03:10" as an example, your derived column would appear as:
(DT_DBTIMESTAMP)(SUBSTRING([column],1,4) + "-" + SUBSTRING([column],5,2) + "-" + SUBSTRING([column],7,2) + " " + SUBSTRING([column],9,2) + ":" + SUBSTRING([column],11,2) + ":" + SUBSTRING([column],13,2))
The resulting output column would appear as:
2012-07-30 02:03:10.000
Recall that any missing values within a given date can be concatenated with the date values within your column. For example, using the string value "2152012 101946", your derived column expression would be written as:
(DT_DBTIMESTAMP)(SUBSTRING([column],4,4) + "- 0" + SUBSTRING([column],3,1) + "-" + SUBSTRING([column],1,2) + " " + SUBSTRING([column],9,2) + ":" + SUBSTRING([column],11,2) + ":" + SUBSTRING([column],13,2) + ".000")
Taking this one step further, since dates in string format often are not clean, you might consider writing a conditional statement which checks the length of a value prior to concatenating & converting the values. For example, if 2012/09/30 11:59pm and 2012/10/01 11:59pm are represented as strings in a column where leading zeros are not present, the strings may appear as:
"2012930 115959"
"20121001 115959"
To account for leading zeros in the month, an if-then-else expression could be incorporated such that:
LEN(column) = 14 ? (DT_DBTIMESTAMP)(SUBSTRING([column],1,4) + "- 0" + SUBSTRING([column],5,1) + "-" + SUBSTRING([column],6,2) + " " + SUBSTRING([column],9,2) + ":" + SUBSTRING([column],11,2) + ":" + SUBSTRING([column],13,2)) : (DT_DBTIMESTAMP)(SUBSTRING([column],1,4) + "-" + SUBSTRING([column],5,2) + "-" + SUBSTRING([column],7,2) + " " + SUBSTRING([column],10,2) + ":" + SUBSTRING([column],12,2) + ":" + SUBSTRING([column],14,2))
Note that the above expression does not take values that have a length less than 14 characters or greater than 15 characters into account. In this case, you could expand the above if-then-else expression to nest additional expressions for varying lengths.
In reporting services, I have used
=IIf(Fields!Weekday.Value="Su"
or Fields!Weekday.Value="Sa"
or Len(Fields!HOLIDAY.Value)>0,
(Fields!GENERAL.Value
+ Fields!LAUNCH.Value
+ Fields!SHIFT.Value
+ Fields!OCESAWE.Value
+ Fields!OCESAWD.Value
+ Fields!WEPHWORK.Value
+ Fields!OCREMWE.Value
+ Fields!OCREMWD.Value) * 1.5,
(Fields!GENERAL.Value
+ Fields!LAUNCH.Value
+ Fields!SHIFT.Value
+ Fields!OCESAWE.Value
+ Fields!OCESAWD.Value
+ Fields!WEPHWORK.Value
+ Fields!OCREMWE.Value
+ Fields!OCREMWD.Value)
)
To get a columnn called "Total Weighted" and this column have several rows.
1. ID Total Weighted
2. 111 21
3. 121 49
How can I get the total of the "Total Weighted?
Create a calculated field in your dataset, and use the formula you provided as the value of that field. Now you can refer to that field elsewhere as if it came from your database.
So then you'd use an expression like =SUM(Fields!TotalWeighted.Value) in your tablix.