2

Here are my columns in my table SystemSpecCategories

 ID (int) 
 Group ID  (int)
 Description   (varchar)

My GroupID has values from 1-9. I would like to run a query that changes all GroupID values that are 8, and change them to 9. I am very new to SQL and I have tried :

 UPDATE SystemSpecCategories
 SET GroupID = 9
 WHERE GroupID = 8

This through the error "8" is not a valid column name I think I may be way off with that query but Ive tried another with REPLACE

 SELECT REPLACE(Group_ID, "8", "9")
 FROM SystemSpecCategories

I thought I was straight on with that one but it through an error saying incorrect syntax. Could anyone help me out? Id greatly appreciate it.

2
  • Your first attempt was correct. UPDATE lets you change the values in the table. SELECT is read only. I do note your list of columns says "Group ID" with a space. Can you provide the actual CREATE TABLE command? Commented Jan 26, 2012 at 21:20
  • REPLACE computes a string replacement; it doesn't do anything to the DB. Commented Jan 26, 2012 at 21:22

2 Answers 2

2

Your first try is correct.

The problem might be that your column is called Group ID (with a space).

If that is case, try:

UPDATE SystemSpecCategories
SET [Group ID] = 9
WHERE [Group ID] = 8
Sign up to request clarification or add additional context in comments.

Comments

0

It is better if you always add "_" when you have a column name which is same as a sql statement.

UPDATE SystemSpecCategories SET GROUP_ID = 9 WHERE GROUP_ID IS 8;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.