data will be read from excel sheet & store data table& i will insert data in database(oracle).but term column in database accept 7 bytes like mm/yyyy . but my input read data will be date time format.how can i do date time to mm/yyyy
below is oracle insert query
strQuery &= "'" + String.Format("{%M/%y}", dt1.Rows(row)("TERM")) + "',"
When you read the date/time from excel, assign the value to datetime variable and then you can pull the month and year from.
Related
I have excel which i am trying to import in oracle database table.
Some of the values in excel consist of for example 14:39.5 with double colon. What dataype in oracle database table i should provide to store this value ?
Currently have given varchar datatype and its throwing an error during import as :
Conversion error! Value: "00:12:01.615518000" to data type: "Number". Row ignored! Value is '00:12:01.615518000'. Cannot be converted to a decimal number object. Valid format: 'Unformatted'
You can store it as an INTERVAL DAY(0) TO SECOND(9) data type:
CREATE TABLE table_name (
time INTERVAL DAY(0) TO SECOND(9)
);
Then you can use TO_DSINTERVAL passing your value with '0 ' prepended to the start:
INSERT INTO table_name (time)
VALUES ( TO_DSINTERVAL('0 ' || '00:12:01.615518000') );
db<>fiddle here
If it is part of a date/time stamp then you could store it as DATE or TIMESTAMP if you could add the date component. Oracle doesn't have just a TIME data type.
If you can't add a date component to it, then assuming it is a time interval you could convert it to seconds or microseconds (lose the colons) and store it as a NUMBER.
If you want to maintain the exact formatting as shown, your only option is to store it as text using VARCHAR2 or something similar.
I am trying to fetch data from my Access table into Excel sheet. The below mentioned SQL query is throwing an error "Data type mismatch in criteria expression" while the execution reaches Open query.
I googled for all possible fixes. All are saying the number might be passed in quotes. i checked for it still clueless, The query is pretty simple where i am trying select data from a userform text box in DD-MMM-YYYY format (03-OCT-2018) and comapring with date portion of timestamp field and order by my customer id field
SELECT * FROM Master_Intrpay_Cash where DateValue(LAST_UPDATE_TIMESTAMP)>=#" & Trim(startdate.value) & "# and DateValue(LAST_UPDATE_TIMESTAMP)<=#" & Trim(enddate.value) & "# ORDER BY CUSTOMER_ID
Below Shown is the msgbox showing the query being passed. if it helps.
Also the crazy part is the above query was copy pasted from an existing working query, just changed the table name and timestamp field name. Rest everything is exactly the same.
Try without DateValue:
SELECT *
FROM Master_Intrpay_Cash
WHERE LAST_UPDATE_TIMESTAMP >= # " & Trim(startdate.value) & " #
AND LAST_UPDATE_TIMESTAMP <= # " & Trim(enddate.value) & " #
ORDER BY CUSTOMER_ID
DateValue expects a String as an argument, your column as Date/Time
Also, a preferable format for the date is #mm/dd/yyyy# (US date format), otherwise you may have problems with different locales.
I am trying to get a data from Excel using C#. My Excel data contains several records but I need the data which is between two dates.
I tried with the following code :
OleDbCommand cmd=new OleDbCommand("select field1,field2,joiningdate from [Sheet1$] where joiningdate >=to_date('"+startDate+"','MM/DD/YYYY') and joiningdate <=to_date('"+endDate+"','MM/DD/YYYY')", con);
I can get the values of startDate and endDate through DateTimePicker control..
Try the following query:
select field1,field2,joiningdate from [Sheet1$]
where joiningdate between CDate(startDate) and CDate(endDate)
This is assuming that your joiningdate column is formatted as Date type.
I have to import data from Excel file to SSIS but i am facing a problem in date column,in excel sheet date format is yyyy/mm/dd and when it gets upload in database it get change into yyyy/dd/mmm format.
How to fix this?
Use the SUBSTRING function in the derived column while importing the date,
(LEN(TRIM(SUBSTRING(ReceivedDateTime,1,8))) > 0 ? (DT_DBDATE)(SUBSTRING(ReceivedDateTime,1,4) + "-" + SUBSTRING(ReceivedDateTime,5,2) + "-" + SUBSTRING(ReceivedDateTime,7,2)) : (DT_DBDATE)NULL(DT_WSTR,5))
If the Data is there then use Substring function to extract the exact date that sets in the DB or if the date does not exist then insert NULL in the DB.
I see two options:
Data Conversion Transformation to convert to a text string in
the appropriate format. Using SSIS data types.
Add a script task that converts the data type. Using VB data types
First Create Table into Your Database Using below Command
CREATE TABLE [dbo].[Manual] (
[Name] nvarchar(255),
[Location] nvarchar(255),
[Date] datetime
)
SET DATEFORMAT YDM
By using DATEFORMAT YDM ,Date Will import in YYYY/DD/MM Format .Before runnung package modify the package and at the time of Column mapping select The Check Box "Delete Rows in Destination Table" .
Then Execute the Package . It Will work .
I'm using ADODB connection in VBA excel file with Microsoft.Jet.OLEDB.4.0 provider.
The file with which I'm establishing connection is .csv file which looks like:
Date and time, Last name, First name
2011-08-29 05:48:50,lname1,fname1
2011-08-29 05:49:50,lname1,fname1
2011-08-29 05:55:50,lname2,fname2
2011-08-29 16:11:50,lname1,fname1
2011-08-29 17:55:50,lname2,fname2
2011-08-30 9:11:50,lname1,fname1
The point is that my data is sorted by Date and time which is in one field, and user names are not in any order.
What I really need to do is create a query to fill Recordset.
I need this query to select first, second and last hour for each day for each user name.
Is it even possible to split Date and time column just using a query?
I've got general idea how to select what I want, but the thing is too complicated for me, because of that Date and time in the same field.
Would you give me any suggestions?
Let us say your file is called Dates.csv, you can try:
SELECT
[Last name] & ", " & [First Name] AS FullName,
Format([Date And time],"yyyy/mm/dd") AS WorkingDay,
First(Format([Date And time],"hh:nn:ss")) AS FirstHour,
Last(Format([Date And time],"hh:nn:ss")) AS LastHour
FROM [Dates.csv]
GROUP BY [Last name] & ", " & [First Name], Format([Date And time],"yyyy/mm/dd")
I am a little suspicious of the double space between date and time. I would get rid of the spaces in the column names, if I were you. It will make things easier.