I am trying to fetch 30 days back results from today in order to see who have not paid last month.
I tried something
SELECT * FROM MemberInformation WHERE DateOfAd = 'DATEADD(Day,-30,getdate())'
and query successfully executed but did not fetch the values I wanted.
My database:
please guys help me out...
DATEADD is not work in sqlite you but you can use its sqlLite equivalent DateTime like code below :
select * from TableName where DateColumn < DateTime('Now', 'LocalTime', '-10 Day');
http://www.sqlite.org/lang_datefunc.html
SQLite equivalent of SQL Server DateAdd function
Try
SELECT * FROM MemberInformation WHERE DateOfAd BETWEEN datetime('now', '-30 days') AND datetime('now', 'localtime');
or Try to change where condition as,
WHERE DateOfAd BETWEEN datetime('now', 'localtime', '-30 days') AND datetime('now', 'localtime');
Related
String sql1="SELECT MAX(date),epf_rte_emp,epf_rte_com,etf_rte FROM Fixed_Rates1";
I'm using this query to select the record with the maximum date value, but it gives the latest updated record. I want the record with the maximum date.This query gives the record with maximum date in the SQLiteManager, but doesn't gives the required output in netbeans. Could someone please help me in this?
If you want one record, then something like this shoudl work:
select fr.*
from fixed_rates1 fr
order by date desc
limit 1;
Note: I am guessing you are using MySQL, because your query would fail in most other databases. The method for limiting results depends on the database.
If you want all rows with the maximum date:
select fr.*
from fixed_rates1 fr
where fr.date = (select max(fr2.date) from fixed_rates1 fr2);
I have this sql query which runs fine and return 3 rows when run on sql developer but when I execute the same query in a jsp page, it executes properly but doesn't return any rows. There is no problem with database connection because all other queries work fine.
Server - Tomcat 7
database - Oracle 10g
query -
select slno from lbk_tab where log_date = to_date('18-06-2017','DD-MM-YYYY')
jsp -
String dtol = "select slno from lbk_tab where log_date = to_date('18-06-2017','DD-MM-YYYY')";
Statement st = connection.createStatement();
ResultSet resultSet = st.executeQuery(dtol);
if (resultSet.next()) {
out.print(Integer.parseInt(resultSet.getString(1)));
}
Table lbk_tab has columns slno and log_date.
How can I fix this?
Try these things :
Classfiles are being generated afresh ? Clear & re-build project /
workspace.
Print the query and try to run printed query. Theoretically it looks the same from code, but just to be sure..
Check for query being fired at database also, may be java messes
with date object or date format. Hence the actual date fired from jsp says something else while fired at mysql points at something else ? debug / log / print query actually fired at mysql
end.
More clarity is required here, "to_date" referenced in query is
function ? what are column types.
I Think you need to use to_char()
select slno from lbk_tab where log_date = to_char(to_date('18-06-2017','DD-MM-YYYY'))
Good day, I am struggling with an sql select query from my java application. My application connects with an MS Access database. I would like to retrieve all records logged during a specific month. This is my statement:
Select * from tbl q
Join (
Select s.Customer from tbl s
Where Month(s.LogDate) = 1 And Year(s.LogDate) = 2017);
Problem is that my resultset returns data logged for both January 2017 and December 2016. I have tried different approaches one of which was to pass an sql date(#date#) but I still get the same result. What am I doing wrong?
You shouldn't need the join or the subquery. Try
Select * from tbl where month(logdate)=1 and year(logdate)=2017
I need to fetch records of last month using hql earlier i used to fetch records using sql query but now i need to fetch records of 1 month span.for example today's date is 15-Dec-2014 I want to get records between 15-Nov-2014 to 14-Dec-2014 records.
Here is Mysql query:
SELECT fds.EXISTED_PRODUCT_ID,fds.Product_Name,fds.PRODUCT_CREATED_DATE FROM
F_PRODUCT_DATA_STATISTICS fds where fds.CREATED_TS BETWEEN
SUBDATE(CURDATE(), INTERVAL 1 MONTH) AND NOW()
Frankly, I don't have any idea about how to write above query in HQl.
Can anyone please help me.
Could you try this, I couldn't test, if you it has a error please inform me;
String hqlQuery =" SELECT fds.EXISTED_PRODUCT_ID,fds.Product_Name,fds.PRODUCT_CREATED_DATE FROM F_PRODUCT_DATA_STATISTICS fds where fds.CREATED_TS BETWEEN DATE_SUB(current_date(), INTERVAL 7 DAY) AND current_date()";
query = session.createSQLQuery(hqlQuery);
I am using java swing and mysql database for my desktop based application.
And i am having following query while giving date filter on reports.
If I have not enter To_date to From_date in JTextField then it must show all records from my mysql database table and if i have entered date then it must show records in between that two dates.
So i have tried (date between To_date and From_date) But its showing records only when i give dates to query otherwise empty.
Would you please suggest me something?
You should try some static value for date column if its null.
I hope below query will help you to resolve your issue.
SELECT * FROM YourTable WHERE IFNULL(#StartDateParameter, IFNULL(DateColumn,'1900-01-01')) <= IFNULL(DateColumn,'1900-01-01')
AND IFNULL(#EndDateParameter, IFNULL(DateColumn,'1900-01-01')) >= IFNULL(DateColumn,'1900-01-01')
Please let me know if you cant solve your issue with this query.
You can use IFNULL ( http://www.mysqltutorial.org/mysql-ifnull/ ) and form your query such that if your parameter is null then you should use your column value for comparison.
e.g.
SELECT * FROM YourTable WHERE IFNULL(DateColumn,#YourParameter) = #YourParameter