SSIS Convert string to DateTime dd/mm/yyy hh:mm:ss - sql-server-2008

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.

Related

Why does SQL operation shows the same output? [duplicate]

This question already has answers here:
Compare dates in MySQL
(5 answers)
Closed last year.
when I output these two SQL operations, the columns for the two months (01 = January) and (02 = February) are summed together instead of individually. So they show the same output. But why?
If if want to output (02 February) it should not show the sum of January but it does. Where is my problem in my code?
"SELECT SUM(" + dataBaseHelper.GET_SUM + ") FROM " + dataBaseHelper.TABLE_NAME + " WHERE " + dataBaseHelper.DATE + " BETWEEN '01/01/2022' AND " + "'07/01/2022'"
and
"SELECT SUM(" + dataBaseHelper.GET_SUM + ") FROM " + dataBaseHelper.TABLE_NAME + " WHERE " + dataBaseHelper.DATE + " BETWEEN '01/02/2022' AND " + "'07/02/2022'"
The standard syntax for date in MySQL is yyyy-mm-dd. I think you could replace the dates in your where between statement using this consideration. Otherwise read string to date cast specifications.

SSRS - trying to get total rows by using CountRows function

I am trying to get the total rows returned by each tablix. Each row returned is an error and I need to get the total errors. Each tablix has it own data set name so I am trying to use CountRows(data set) and add them together to get the total rows returned or total errors.
Code:
="Number of Errors: " & CountRows("Reader_Check")'' + '' & CountRows("Access_Panel_Check")'' + '' & CountRows("Reader_Check")'' + '' & CountRows("Alarm_Panel_Check")'' + '' & CountRows("Alarm_Input_Check")'' + '' & CountRows("Alarm_Output_Check")'' + '' & CountRows("Segment_Check")'' + '' & CountRows("Access_Level_Check")'' + '' & CountRows("Area_Check")'' + '' & CountRows("Timezone_Check")'' + '' & CountRows("Alarm_Check")
Any help would be great. Thanks
It looks like you are appending the + as a string?
I think you just need something like
="Number of Errors: " &
(CountRows("Reader_Check")
+ CountRows("Access_Panel_Check")
+ CountRows("Reader_Check")
+ CountRows("Alarm_Panel_Check")
+ CountRows("Alarm_Input_Check")
+ CountRows("Alarm_Output_Check")
+ CountRows("Segment_Check")
+ CountRows("Access_Level_Check")
+ CountRows("Area_Check")
+ CountRows("Timezone_Check")
+ CountRows("Alarm_Check")
)
Note: you have Reader_Check specified twice which I assume is incorrect

How to convert CYYMMDD to YYYY-MM-DD in SSIS?

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:

Formatting dates for Insert into MYSQL with Node.js

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.

Totalling based on expression field

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.