Reputation: 1205
insert into product (CategoriesId) values (2) where Categories=' ab '
error is
Incorrect syntax near the keyword 'where'.
i cannot understand please help me
Upvotes: 4
Views: 34172
Reputation: 397
If you want to update the username or in the main while you are not inserting the record. so use update query instead of insert query and for insert query Where clause is not used. Try this you can get your ans.. Good luck.
Upvotes: 5
Reputation: 1034
You can not use where clause with insert , You should use update like this
update product set CategoriesId = 2 where Categories='ab'
Upvotes: 5
Reputation: 31239
You can not have a where statement on the insert. If you are using a table then you can.
INSERT INTO product (CategoriesId) values (2)
Or like this:
INSERT INTO product (CategoriesId)
SELECT CategoriesId
FROM someTable
WHERE someTable.Categories=' ab '
Or if you have existing rows and want to UPDATE
them. Then do this:
UPDATE product SET CategoriesId=2 WHERE Categories='ab'
Upvotes: 7