Is this valid SQL? [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'd like to update a table row where:
Either statement1 is true OR statement2 is true
AND independent of which one of those are true, statement3 is also true.
Would this be a valid way of writing this SQL statement?
$upadte = "UPDATE table SET
header = 'value'
WHERE (statment1 = 'true' OR statment2 = 'true') AND statement3 = 'true'";

Yes the SQL is correct in the where part, but I think the 'true' must be true without "'" because if it's wrapped in '' will be interpreted as a string expresion rather than a boolean. The (A OR B) will return true if A or B are true, and if they are true. This condition is checked first because of the parenthesis. Then the thir statetment will be checked and if is true, the complete expression will return true.
$upadte = "UPDATE table SET
header = 'value'
WHERE (statment1 = true OR statment2 = true) AND statement3 = true";

Related

how to fill down when empty cells in access db [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
db access table
kindly i need help to fill down with previous string PS: i am a beginner
Your Date field seems to be of data type Text. If so, change that to DateTime.
Then you can run a loop to update the records having no date value:
Dim Records As DAO.Recordset
Dim Sql As String
Dim LastDate As Date
Sql = "Select * From YourTable Order By [Surevey ID]"
Set Records = CurrentDb.OpenRecordset(Sql)
If Records.RecordCount > 0 Then
LastDate = Date ' Adjust if needed.
Records.MoveFirst
While Not Records.EOF
If IsNull(Records!Date.Value) Then
Records.Edit
Records!Date.Value = LastDate
Records.Update
Else
LastDate = Records!Date.Value
End If
Records.MoveNext
Wend
End If
Records.Close

UPDATE statement in SQL half working half not doing anything [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
So I can't for the life of me figure out what the heck I'm doing wrong. The words, A LOT, comes to mind. But right now I have got half of the UPDATE to work but can't get the rest of it to work.
DoCmd.SetWarnings True
If Me.butCompleteFlight.Value = True Then
SQL = "UPDATE tblFlightRecords SET strLand = values('" & Me.strStopTime & "') WHERE strWorkingRecord = TRUE"
SQL = "UPDATE tblFlightRecords SET strWorkingRecord = FALSE WHERE strWorkingRecord = TRUE"
DoCmd.RunSQL SQL
End If
DoCmd.SetWarnings True
the strWorkingRecord switching from TRUE to FALSE works. The issue I'm having is the strLand is not populating, I used the same syntax as the INSERT sql that I used in a different section of the database but can't find out what I'm messing up on this one.
Thanks
SQL is a string and you assign 2 values to it one after the other. When you execute DoCmd.RunSQL SQL it contains the last value that you have assigned to it.
Execute each statement separately:
SQL = "UPDATE tblFlightRecords SET strLand = '" & Me.strStopTime & "' WHERE strWorkingRecord = TRUE"
DoCmd.RunSQL SQL
SQL = "UPDATE tblFlightRecords SET strWorkingRecord = FALSE WHERE strWorkingRecord = TRUE"
DoCmd.RunSQL SQL
Or you can do it in 1 statement like this:
SQL = "UPDATE tblFlightRecords SET strLand = '" & Me.strStopTime & "', strWorkingRecord = FALSE WHERE strWorkingRecord = TRUE"
DoCmd.RunSQL SQL
Also the VALUES clause in an UPDATE statement is wrong. You can use it only in an INSERT statement.

order by charindex >0 and SQL concat [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I want to order Recordset by setting priority when ID is in an array:
This is the comma separated myString which holds a series of ID: ,1,2,4,6,8,12,34,
I use concat to add comma before and after ID so I can compare it against the string:
sql="select * from customers order by case when charindex( concat(','," & id & ",',') , '" & myString & "' )>0 then 1 else 0 end desc"
I get syntax error message. I am not sure if there is error in SQL structure as I used concat in deep structure or there is error in using quote and double quote?
I found the problem when trying to answer #Diado Comment. The parameter ID should be used in SQL context not as a variable in VbScript context. So I have changed the query to this and it works:
sql="select * from customers order by case when charindex( concat(',',id,',') , '" & myString & "' )>0 then 1 else 0 end desc"

VBA - SQL query with dates as variable on Oracle DB [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am performing in VBA an SQL query selecting per date. Everything is working until I specify the dates, as the code below:
conn.Open dbConnectStr
StartDate = "01/01/2015"
SQL_String = "SELECT * FROM database " & _
"WHERE date BETWEEN to_date('01/01/2015','dd/mm/yyyy') and to_date('31/12/2016','dd/mm/yyyy')"
recset.Close
conn.Close
But, when I put in a variable instead of dates I obtain an error multiple-step operation completed with one or more errors. Check each status values.
conn.Open dbConnectStr
StartDate = "01/01/2015"
EndDate = "31/12/2016"
SQL_String = "SELECT * FROM database " & _
"WHERE date BETWEEN to_date('" & StartDate & "','dd/mm/yyyy') and to_date('" & EndDate & "','dd/mm/yyyy')"
recset.Close
conn.Close
Anybody could suggest how to proceed?

SQL with variable in LIKE statement: Invalid column Index [duplicate]

This question already has answers here:
Using "like" wildcard in prepared statement
(6 answers)
Closed 4 years ago.
I'm using Oracle.
PreparedStatement pstmt = con.prepareStatement("SELECT * FROM BookLoanInfo WHERE title LIKE '%?%' ORDER BY bid");
ResultSet rs;
String bookstring = scan.nextLine();
try{
pstmt.clearParameters();
pstmt.setString(1, bookstring);
rs = pstmt.executeQuery();
The actual problem seems to be with either the setString or how I have typed the query.
This however gives Invalid Column Index.
You'll need to specify the wildcards as part of your setString statement.
Wildcard in Prepared Statement