how to get data within a specific date range from Excel - excel

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.

Related

MS Access - Multiple Queries shared Criteria in time stamp date range

MS Access 2016,
I have Multiple queries - approximately 120 - that are gathering temp history based on date criteria that I currently update manually for each query - >=#8/1/2021# And <#9/1/2021# - for the month of August 2021.
What would be the best solution to update this in one place so all queries could refer to that one date range?
Sample Query: (Usually 43 parameter points)
SELECT
History1HourAverage.TimeStamp,
History1HourAverage.Parameter001,
History1HourAverage.Value001,
History1HourAverage.Parameter002,
History1HourAverage.Value002,
History1HourAverage.Parameter003,
History1HourAverage.Value003,
History1HourAverage.Parameter004,
History1HourAverage.Value004
FROM History1HourAverage
WHERE
(
(
***(History1HourAverage.TimeStamp)>=#8/1/2021#
AND (History1HourAverage.TimeStamp)<#9/1/2021#
)***
AND ((History1HourAverage.Parameter001)="10S8MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter002)="10S9MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter003)="10S10MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter004)="10S11MApp.nvoSpaceTemp")
);
Thank you
A couple of options:
Either
Add a table called DateRange with two fields, StartDate and EndDate. Enter one record in that table with the date range that you want to use for your queries. Edit each of your queries and include the DateRange table. Set the criteria for the query to WHERE History1HourAverage.TimeStamp >= DateRange.StartDate And History1HourAverage.TimeStamp < DateRange.EndDate
Alternatively
Create a VBA module with two functions
Public Function StartDate() As Date
StartDate = #8/1/2021#
End Function
Public Function EndDate() As Date
EndDate = #9/1/2021#
End Function
Set your query criteria for the query to WHERE History1HourAverage.TimeStamp >= StartDate() And History1HourAverage.TimeStamp < EndDate()
When you want to use a different date range you either (1) edit the data in DateRange table, or (2) edit your functions to return the new dates.

Get last item with date range and name filter in google sheets

I have the below set of records in Google Sheets. I would like to filter the rows with specific name and date range. Once I have the filtered data, I would like to fetch the last row's final amount cell data.
Ex: I would like to fetch final amount as 300 if my date(dd/mm/yyyy) range is 01/01/206 to 11/06/2016 and Name selection is 'Sandeep'.
As I have experience SQLite db, I have inserted the same records in DB and got the expected result using the below query.
select Final from MyTable where Date in (select max(Date) from MyTable WHERE Date BETWEEN '01/01/2016' AND '11/06/2016' and name = "Sandeep")
But I am not getting idea how to use multiple select statements in google sheets. It is ok for me to get result using any other way. So please help me to get the result as explained above.
= QUERY (A1:E50,"Select F where A > date '2016-1-1' and A < date '2016-6-11' and B ='Sandeep' order by A desc limit 1")
Use Column IDs A,B,C instead of name, income. Multiple columns can be given in a single Select clause separated by a ,
Dates in where clause should be written in yyyy-mm-dd format only(regardless of the format of dates in actual column)
See if this works
=index(E:E, max(filter(row(A:A), A:A>date(2016, 1, 1), A:A<date(2016, 6, 11), B:B="Sandeep")))
If you want to include start and end date, change > to >= and < to <=.

convert date time to month/yearin oracle query in vb.net

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.

Adapt SQL Query with an Excel valua

I'm using Excel 2013 to get data from a SQL Server 2012 database,
I successfully get data using an SQL Query, but now I want that query to be dynamic, based on the Month and Year.
How is it possible to use a cell value (a spreadsheet cell) as a parameter for such a query?
I use this Query:
SELECT [Class_02] AS [MS Part Number]
,[701].[dbo].[ItemClasses].[Description] AS [Item Name]
,ROUND([701].[dbo].[frhsrg].[esr_aantal]/3, 0) AS [Aantal]
,[701].[dbo].[ItemAccounts].[SlsPkgsPerPurPkg] AS [Prijs]
,SUM(DISTINCT [701].[dbo].[frhsrg].[esr_aantal]) * [701].[dbo].[ItemAccounts].[SlsPkgsPerPurPkg] as Totaalprijs
FROM [701].[dbo].[Items]
WHERE DATEPART(YEAR, fakdat) = '2013'
AND DATEPART(QUARTER, fakdat) = '1'
AND [701].[dbo].[frhsrg].[docnumber] LIKE '%kwartaal%'
I have two values in Excel (Month and Year) like March 2013, and then the DATEPART statement in SQL has to be based on that. I use the Excel 2013 Add-In PowerPivot to fill the Excel sheet with the SQL Query output. How does the SQL Query need to be to do this?
In forward, many thanks!
... I you have the query saved as a string in your Excel VBA macro (I'm assuming that is where this query is run from), simply write it as follows:
WHERE DATEPART(YEAR, fakdat) = <<YEAR>>
AND DATEPART(QUARTER, fakdat) = <<MONTH>>
Basically having <<YEAR>> and <<MONTH>> as placeholders, then you can just use the Replace function looking something like this:
Replace strSQL, "<<YEAR>>", Range("A1").Text
where strSQL would be the SQL string
Customize a parameter query - http://office.microsoft.com/en-us/excel-help/customize-a-parameter-query-HP010216113.aspx

Date format issue in ssis

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 .

Resources