I'm debugging an app with the following code:
sql = myTable
Set datTable.Recordset = myDB.openRecordset(sql, dbOpenDynaset, dbSeeChanges)
where
sql = "select * from table Order by Precipition,Date/Time"
An error occurs on the second line saying "Run-time error '3061': Too few parameters. Expected 2". I believe the issue is the with the value of sql. I don't know to much about SQL, so does anyone have any ideas?
I thingk you can try
sql = "select * from table Order by Precipition,[Date/Time]"
Note the "[]"
You should try to avoid using table names/columns that contains spaces, or keywords, as this will make life very dufficult.
Use name that explain the field in context to the table.
The problem is in your order clause: more specifically here:
Date/Time.
Related
When I update a column using phpmyadmin in database with following query
UPDATE members
SET `refered` = (SELECT COUNT (*)
FROM `user_details`
WHERE `user_details.sponser`=`members.username`
)
It show a error message like this
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '*) FROM `user_details` WHERE `user_details.sponser`=`members.username`)' at line 1
What may be reason?
Error is in
COUNT (*)
-----^
Remove the space between COUNT and (*).
Try the below query
UPDATE members SET refered = (SELECT COUNT(*) FROM user_details
WHERE user_details.sponser=members.username)
Does the Select query returns any result. If so what is the result. Looks like all your query is inside '' single quotes that you are using it should be removed. Single quotes need to be removed for example .
UPDATE members
SET refered = (SELECT COUNT (*)
FROM user_details
WHERE user_details.sponser=members.username
)
-- there is not single quotes in the query above. please remove it from yours.
Part of your problem, or maybe the whole problem, is the WHERE clause. You've used backticks for the table name, which is correct (or, at least, it's optional in this case; it's needed if your database name or table name has a MySQL reserved name or is otherwise ambiguous). The problem, though, is that the dot separating the database from the table needs to be outside the backticks. So your WHERE clause should look like this instead:
WHERE `user_details`.`sponser`=`members`.`username`
I'm looking at some sql code with the following structure:
set #var =
(
select count(1) from
(
select * from table where field = 1
)
someVariable
)
It won't seem to run unless "someVariable" is in the statement. My question is, what does this "someVariable" represent, and why is it in the query? I don't understand why I can't set #var to the select count statement outright, so the "someVariable" is really throwing me off.
Derived tables need to have aliases. someVariable is functioning as an alias in this case.
When I run a similar query on MySQL, I got:
ERROR 1248 (42000): Every derived table must have its own alias
The inner select actually gives rise to a derived table, and someVariable is it's alias.
I'm trying to run a statement where I retrieve tuples from a database. However my attribute has a space which is "State Name".
Im calling the SQL statement as follows:
select * from States where State Name = 'Michigan';
I'm pretty sure there is something wrong with the attribute having a space. How can I fix this problem without changing the name of the attribute? How can I call a SQL statement with the attribute constraint having a space?
Thanks,
select * from States where [State Name] = 'Michigan';
Try throwing square brackets around it:
select * from States where [State Name] = 'Michigan';
The Standard SQL delimiter (and supported by SQL Server) is the double quote e.g.
SELECT *
FROM States
WHERE "State Name" = 'Michigan';
I am trying to update a value in my database but am recieving the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''users' ('new_user') VALUES ('1') WHERE 'id'= 5' at line 1
I am trying to UPDATE the table 'users' in the column 'new_user' where the id is equal to $userid. But it don't work. Please help.
$newuservalue = '1';
$notnewuser ="UPDATE 'users' ('new_user') VALUES ('$newuservalue') WHERE 'id'= $userid ";
$query2 = mysql_query($notnewuser) or die(mysql_error());
Well, your syntax is wrong.
It should be:
UPDATE table_name SET field1=new-value1, field2=new-value2 [WHERE Clause]
So, remove the "values" part of your query and put in the "set" part.
Here's a link to the official documentation.
i have that problems some times, that's the code to insert a new row :d
It should be:
UPDATE users SET new_user='$newuservalue' WHERE id=$userid
you also don't need to put quotes around your column names, that might give some problems as well.
when i give this sql query in my msaccess database table called warehouse1 it gives this error
"operation must use an updateable query?"
UPDATE warehouse1 SET STD_MOU = "?"
WHERE warehouse1.[STD_MOU]="null";
what could be the reason ?
Alternative interpretations of the SQL given:
As posted: find the fields with the literal word "null" in them and replace them all with the literal question mark.
Ask the user for the value they want to replace all Nulls with: UPDATE warehouse1 SET STD_MOU = [?] WHERE warehouse1.[STD_MOU] Is Null;
Ask the user for the value they want to replace the word "null" with: UPDATE warehouse1 SET STD_MOU = [?] WHERE warehouse1.[STD_MOU]="null";
I don't find any of these to be particularly advisable. This would be OK, though:
UPDATE warehouse1 SET STD_MOU = Null
WHERE warehouse1.[STD_MOU]="null";
Nulls are good and shouldn't be avoided at all.