I am stuck at a place where i am able to proceed with a sqlite SELECT query. My query is like this. I dont know if it tis correct or wrong. Please help me.
NSString *querySQL = [NSString stringWithFormat: #"SELECT * FROM CLAIMS WHERE DATE = \"%#\" AND TIME = \"%#\"",splitdate,splittime];
Any help is appreciated.
Thanks
SQL uses ' for strings, so at the very least your query should look like:
SELECT * FROM CLAIMS WHERE DATE = '%#' AND TIME = '%#'
A further step would be to make those things parameters:
SELECT * FROM CLAIMS WHERE DATE = #date AND TIME = #time
And a further improvement is to use the SQL type datetime for the field so you'll only need one instead of 2:
SELECT * FROM CLAIMS WHERE DATE = #date
Related
I am a new developer in asp.net, I want to create query that retrieve row based on comparing between DateTime (column in my table) with the current date, I used a lot of things like:
Select * from employee where DateTime = dateadd(dd,0, datediff(dd,0, getDate()))
Select * from employee where DateTime=Convert(date, getdate())
Select * from employee where DateTime =getDate()
The first one, worked correctly but suddenly did not work!
what do you think is the problem?
Try your query like this
Select * from employee where convert(date,yourfield) = convert(date,dateadd(dd,0, datediff(dd,0, getDate())))
You can use CASTto trim time part from the date for the sake of searching.
SELECT * FROM Employee WHERE CAST(DateTime AS DATE) = CAST (GETDATE() AS DATE)
This is OrientDb 2.1.4.
The following query works fine:
select from SyncableHist where history_date <= date('2016-04-12 21:25:17','yyyy-MM-dd HH:mm:ss')
and returns as expected three records and each records has the value of history_date = '2016-04-12 21:25:17'. The history_date is a DATETIME type.
However this does not return any records:
select from SyncableHist where history_date = date('2016-04-12 21:25:17','yyyy-MM-dd HH:mm:ss')
Any ideas???
Thanks!
Format your date to string before compare. Not sure why, but probably have something extra like miliseconds or your database can't compare both this way.
select from SyncableHist where history_date.format('yyyy-MM-dd HH:mm:ss') = '2016-04-12 21:25:17'
I have a table containing entries with date and time. I try to create a NamedQuery which only compares the date part.
#NamedQuery(name = "Vote.findForDate", query = "SELECT v FROM Vote v WHERE v.createdAt = :date")
...
createNamedQuery("Vote.findForDate").setParameter("date", date, TemporalType.DATE).getResultList();
But it seems that it always tries to compare the whole datetime.
Is there no way without using date() function in SQL?
I try to be independent from the database. For example h2 has no date() function.
One possible solution is the usage of date as column type and reduce the information.
#Column(name = "voteDate")
#Temporal(value = TemporalType.DATE)
private Date voteDate;
I'm using DateDiff() function of ASP to find the date difference between two dates.
The Function works fine and displays the exact date difference between two dates but when it comes to insert this value in the database it takes 9 as the value irrespect of any date difference.
Suppose difference between two dates is more than 15 or 20 days, in the database it takes "9".
I have used INT as the DATA TYPE for the column where it displaying the date difference.
Is DATA TYPE creating an issue here?
I even tried using session variable to store the value but no luck - here's my code below:
if request.Form("sub") <> "" then
sql = "Select * from emp_leave_details"
rs.open sql , con, 1, 2
dim diff
dim todate
dim fromdate
fromdate= rs("leave_from")
todate= rs("leave_to")
session("date_diff")=datediff("d",fromdate,todate)
rs.addnew
rs("emp_name") = request.Form("name")
rs("emp_no") = request.Form("number")
rs("address") = request.Form("address")
rs("contact_no") = request.Form("contact")
rs("mobile_no") = request.Form("mobile")
rs("contact_onleave") = request.Form("contact_details")
rs("leave_type") = request.Form("rad")
rs("other_leave_details") = request.Form("PS")
rs("leave_from") = request.Form("from")
rs("leave_to") = request.Form("to")
rs("applied_by") = request.Form("apply")
rs("accepted_by") = request.Form("accept")
rs("approved_by") = request.Form("approve")
rs("no_of_leave_taken")= session("date_diff")
rs.update
response.Write("<script language='javascript'>{update();}</script>")
rs.close
end if
The datatype has nothing to do with this. Storing the value in the session is not the solution. You can use a regular variable.
From your code it looks like you always use the same values for fromdate and todate. This is because you do not iterate the rows in the resultset.
if not rs.bof and not rs.eof then
do while not rs.eof
'' code to execute for each row
rs.moveNext
loop
end if
In your current script rs will always return the results of the first row returned by the query.
The second problem your running into might be the Date datatype. Convert your value to a date using cDate and use this to calculate the difference.
Your problem is , you search for "Select * from emp_leave_details" which always gives all records from that table. You retrieve the values of the first record and do a diff of these, which results in always the same value, that is normal. From your question it is unclear what you really want to do. I suppose so want so select a record like
Select * from emp_leave_details where emp_name=<%=request.Form("name")%>
and based on that add a new record with a computed no_of_leave_taken.
Sorry guys my bad...
It was the database field name that I was calling instead of
fromdate= request.form("from")
todate= request.form("to")
I was calling this
fromdate= request.form("leave_from")
todate= request.form("leave_to")
Sorry again..but I really appreciate you all for providing me with all that possible solutions.
Thanks.
I am using the following code to get the ID of the latest form application started in my flex app, In the table the column is named id. However the following updates nothing to g.appID. The correct application ID makes it's way to the row Object but not to the g.appID variable. The only property that row appears to have is Max(id) which is the correct value that I need. but when I try g.appID = row.Max(id) I get a error saying Max is not a function, so I cant get either way to work currently. Anyone see what I could be doing wrong? Thanks for any help in advance!
// Get the ID
sqlStatement.text =
"SELECT Max(id) FROM applications";
sqlStatement.execute();
var result:SQLResult;
result = sqlStatement.getResult();
var row:Object = result.data[0];
g.appID = row.id;
Change your SQL to: SELECT Max(id) AS maxID FROM applications This will get you out of doing that wierd subselect your doing. This may also save you some processing depending on how often that query is running.
now change g.appID = row.id; to g.appID = row.maxID; and you should be good to go.