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
Related
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 am trying to import my CSV file into Teradata using Teradata's Fastload script.
I also tried adding an auto-increment column.
This is my CSV file:
Word,country,sale,week
hi,USA,26.17,11/22/15-11/28/15
bye,USA,16.5,11/22/15-11/28/15
code snippet
String tableName = "my_db.mytable";
String createTable = "CREATE TABLE " + tableName + "," +
"NO FALLBACK," +
"NO BEFORE JOURNAL," +
"NO AFTER JOURNAL," +
"CHECKSUM = DEFAULT" +
"(" +
" id decimal(10,0) NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 NO CYCLE),"+
" word VARCHAR(500) CHARACTER SET UNICODE," +
" country VARCHAR(50)," +
" sale FLOAT," +
" week VARCHAR(30)" +
") " +
"PRIMARY INDEX (id)";
// INSERT statement
String insertTable = "INSERT INTO " + tableName + " VALUES(?,?,?,?,?)";
Error i got:
Row 1 in FastLoad table my_db.mytable_ERR_1 contains the following data:
ErrorCode=2673
ErrorFieldName=F_id
ActualDataParcelLength=55
DataParcel: byte array length 55 (0x37), offset 0 (0x0), dump length 55 (0x37)
This doesn't look like a FastLoad script, is this part of a JDBC-FastLoad?
2673 The source parcel length does not match data that was defined.
Your input data is a comma-delimited text, thus you must define all columns as VARCHAR.
And there are four columns in your input file, but you specify five in the INSERT. As the name implies a GENERATED ALWAYS sequence is automatically created.
Im trying to run a Store procedure query to export to CSV file using bcp as a daily task on SQL server
using a normal query works fine for example
select #csv = 'bcp "select * from Table" queryout '+#FileAndPath2+' -c -t, -T -S' +##servername
However when I add my query which is a list of transactions data within a date range it seems to crash
#p_companyId uniqueidentifier = '189be460-99d1-42e9-b4ed-8de6f8724ce8',
#p_Path varchar(300) = 'C:\temp\','
#p_Date datetime = getutcdate
set #FileAndPath2=#p_Path + CONVERT(nvarchar(30), #p_Date, 112) + '_' + CONVERT(varchar(36), #p_companyId) + '_transactionslog.csv';
declare #csv varchar(8000)
declare #csvSQL varchar(8000)
set #csvSQL = 'SELECT TOP (100) [KICSDEV].dbo.MOVIEDETAIL.Title , [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.MemberId, [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.CreateDateTime as ''DateTime'' FROM [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG INNER JOIN [KICSDEV].dbo.MOVIEDETAIL ON [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.MovieDetailId = [KICSDEV].dbo.MOVIEDETAIL.MovieDetailId INNER JOIN [KICSDEV].dbo.MEMBER ON [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.MemberId = [KICSDEV].dbo.MEMBER.MemberId INNER JOIN [KICSDEV].dbo.CINEMA ON [KICSDEV].dbo.MEMBER.CinemaId = [KICSDEV].dbo.CINEMA.CinemaId WHERE ([KICSDEV].dbo.CINEMA.CompanyId = '+ #p_companyId + ' and [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.CreateDateTime >= ' + #p_Date +' and [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.CreateDateTime < DATEADD (day , 1 , '+#p_Date+'))'
select #csvSQL
select #csv = 'bcp "'+ #csvSQL +'" queryout '+#FileAndPath2+' -c -t, -T -S' +##servername
exec master..xp_cmdshell #csv
When I run it comes up as "The data types varchar and uniqueidentifier are incompatible in the add operator." error
When i change the Company to the string instead of the variable in the query it works fine but errors on this.
set #csvSQL = 'SELECT TOP (100) [KICSDEV].dbo.MOVIEDETAIL.Title , [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.MemberId, [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.CreateDateTime as ''DateTime'' FROM [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG INNER JOIN [KICSDEV].dbo.MOVIEDETAIL ON [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.MovieDetailId = [KICSDEV].dbo.MOVIEDETAIL.MovieDetailId INNER JOIN [KICSDEV].dbo.MEMBER ON [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.MemberId = [KICSDEV].dbo.MEMBER.MemberId INNER JOIN [KICSDEV].dbo.CINEMA ON [KICSDEV].dbo.MEMBER.CinemaId = [KICSDEV].dbo.CINEMA.CinemaId WHERE ([KICSDEV].dbo.CINEMA.CompanyId = ''189be460-99d1-42e9-b4ed-8de6f8724ce8'' and [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.CreateDateTime >= ' + #p_Date +' and [KICSDEV].dbo.MEMBERMOVIEPURCHASELOG.CreateDateTime < DATEADD (day , 1 , '+#p_Date+'))'
Conversion failed when converting date and/or time from character string.
I think it something to do with all the delimiters and data types.
Several problems here. Think of the problem this way. You are building a command line parameter for a command line utility, so everything has to be built into a string.
Step 1: Make sure everything is a string before concatenating the query
You are missing some casts Cast(#p_companyId as VarChar(36)) and CAST( #p_Date as VarChar(25)) you also need to quote the cast of the company id and dates in the formatted string. I recommend making a new variable to have the UTC date as a string #p_DateAsStr varchar(25) = CAST( #p_Date as VarChar(25) ), instead of repeating that over and over.
Step 2: String values in the query need to be quoted
Since you are calling BCP you have to format the query as a string, string parameters need to be quoted. You have to use the single quotes because the string to BCP is in double quotes, for instance:
set #csvSQL = 'SELECT .... WHERE CompanyId = '''+ Cast(#p_companyId as VarChar(36)) + ''....'
Step 3: Convert any strings in the query back to native types as needed by built in functions
We are OK with the GUID specified as a string (if we quote it), but for DataAdd we need to convert back from string to date Like this
CreateDateTime < DATEADD (day , 1 , CAST(''' +#p_DateAsStr+''' as DateTime))
[Update] added a quoted string for the date
I've written following code:
Dim date1 As Date
Dim date2 As Date
date1 = Convert.ToDateTime(DatePickerFromDate.Text)
date2 = Convert.ToDateTime(DatePickerToDate.Text)
Dim cnd As New OleDbCommand("SELECT * FROM Sales WHERE Invoice_Date BETWEEN " + date1 + " AND " + date2 + "", om)
om.Open()
Dim da As OleDbDataReader = cnd.ExecuteReader
While da.Read()
ComboBox1.Items.Add(da(0))
End While
da.Close()
om.Close()
I want to retrieve data between two dates that are been taken from two datepickers.
I tried BETWEEN, also i tried >= =< but result was empty though database contains data. Please help where I'm getting wrong
Your code is probably generating an error. When doing this type of querying, you should store the query string after substitution and print it out. You seem to be missing delimiters around the dates. So this may work in your specific case.
New OleDbCommand("SELECT * FROM Sales WHERE Invoice_Date BETWEEN '" + date1 + "' AND '" + date2 + "'", om)
However, you then need to be careful about the format of the dates. The application layer and the database might use different formats. If you are substituting directly into the query string, then use the format YYYY-MM-DD -- it is the ISO standard date format and generally understood.
Even better is to learn how to parameterize queries so you can actually pass in the date values as date parameters.
If you're using MS Access, this should be the syntax...
SELECT * FROM Sales WHERE Invoice_Date>=#" + date1 + "# and Invoice_Date<=#" + date2 + "#"
If you're using MS SQL Server or MySQL, then do something like this...
SELECT * FROM Sales WHERE Invoice_Date>='" + date1 + "' and Invoice_Date<='" + date2 + "'"
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