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
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:
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 from a .csv file to my MySQl database table in eclipse using "load data local infile". However, I am getting the error message shown below.
Exception in thread "main" com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '1894' for column 'startYear' at row 1
Sample Data:
tconst_titles,titleType,primaryTitle,originalTitle,isAdult,startYear,endYear,runtimeMinutes
tt1,short,Carmencita,Carmencita,0,1894,0000,1
tt2,short,Le clown et ses chiens,chiens,0,1892,0000,5
A similar thread mentioned that it has to do with the date values not being in the correct format. However, I have declared "startYear" as a date when creating the table and it should recognize '1894' as a year shouldn't it ?
Code for creating the table:
String sql1 = "CREATE TABLE Titles" +
"(tconst_titles VARCHAR(255) PRIMARY KEY, " +
" titleType VARCHAR(255), " +
" primaryTitle VARCHAR(255), " +
" originalTitle VARCHAR(255), " +
" isAdult TINYINT(1), " +
" startYear DATE, " +
" endYear DATE, " +
" runtimeMinutes INT)";
Code for inserting data from .csv file:
import java.sql.*;
public class populate {
public static void main(String[] args) throws SQLException {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/IMDB","root","user");
Statement stmt = con.createStatement();
String sql =
"load data local infile 'titles.csv' \n" +
" replace \n" +
" into table Titles \n" +
" columns terminated by '\\t' \n" +
" ignore 1 lines";
stmt.execute(sql);
}
}
https://dev.mysql.com/doc/refman/5.7/en/datetime.html says:
The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'.
Your data is only YYYY. This has no month or day, so it's not a date in the format required by MySQL.
If you only want to store a year with no month or day, use the YEAR data type if you have values in the supported range of 1901 - 2155.
If you have other years (like you have 1894), use SMALLINT UNSIGNED.
I have an Excel source with one of the column name Emailid.
I want the output like below example:
'mahesh123#gmail.com'
The output should be
'ma*****23#gmail.com'
As a beginner i am searching for the replacement for function STUFF, in SSIS package...
select
substring(studentEMAILIDid,1,2)
+ replicate('*',len(substring(studentEMAILIDid,1,
charindex(studentEMAILIDid,'#')
-1)-4)
+ substring(studentEMAILIDid,charindex(studentEMAILIDid,'#')-2,2)
+ substring(studentEMAILIDid,charindex(studentEMAILIDid,'#')+1,
len(studentEMAILIDid)
from <tablename>
I tried the above code in SSMS,i am expecting the result through SSIS package without using "Execute SQL Task".
This is the expression I tried:
emailid==
substring(
StudentEMailID,
3,
LEN(right(StudentEMailID,
findstring('#',StudentEMailID + '#')-1
)
)-4,
REPLICATE('*',LEN(LEFT(StudentEMailID,
findstring('#',StudentEMailID + '#')-1))-4))
–
Data:
select N'mahesh123#gmail.com' as email
union all
select N'EmpireAgain#gmail.com'
Derived Column Code:
SUBSTRING(email,1,2) +
REPLICATE("*",LEN(email) - FINDSTRING(email,"#",1) - 4) +
SUBSTRING(email,FINDSTRING(email,"#",1)-2,LEN(email)-(FINDSTRING(email,"#",1)-2) + 1)
Result:
email NewEmail
mahesh123#gmail.com ma*****23#gmail.com
EmpireAgain#gmail.com Em*****in#gmail.com
I have a String variable in VB.NET and it contains a value like
"Date of 9/23/2012 Tot Sec_sale Amt = 29,22,696RM's Wise , Gunadeep=15,83,876 , Purushothaman C.S.=1,12,829 , P.madhusudhanreddy=4,63,933 , Sunil vakayil=6,31,120 , Girish Varghese=33,019 , Debarun Chakraborty=79,288 , Rajiv Varma=18,630, RM's DT Count 1,342"
In application side I am able to view this value. I stored this value in MySQL table column. That column contains a longtext datatype. But I am not able to view the full content. Not able to view the last part RM's DT Count 1,342. It shows like Rm's....
My table structure:
fld_msg longtext
fld_phone varchar(20)
fld_date date
fld_status varchar(45)
fld_type varchar(45)
fld_name varchar(50)
My VB.NET code:
Dim bh_msg As String =
"Date of " + Convert.ToDateTime(txt1.Text).Date +
" Tot Sec_sale Amt = " + strdmy_bh_sec_amt.ToString +
"RM's Wise " + bh_amt_frmt1.ToString + "," +
" RM's DT Count " + str_bh_dt_count.ToString
Most DB Viewer truncate long texts fields (blob, clob, ...) in order to maintain performances. But that's just debug view. The real data, and your program, should use the entire value.
Try to retrieve those values using your VB code. It should work