SQLTeam.com | Weblogs | Forums

How to update a user group id once created


#1

Please can someone assist,

I've ran the following command which has been working ok.

INSERT INTO tbUser (UserName,UserLogin,UserGroupId)
VALUES ('TestPaul','domain\tuser',9);

Now I need to update the 'userGroupid only' to another number for this specific user 'TestPaul' e.g from 9 needs changing to 44.
How do I go about this, I tried changing INSERT INTO to UPDATE but the syntax is not correct?


#2

The syntax for UPDATE is very different to INSERT.

Here's an Example, and the Microsoft DOCs for UPDATE statement

https://docs.microsoft.com/en-us/sql/t-sql/queries/update-transact-sql#a-namelimitingvaluesa-limiting-the-rows-that-are-updated


#3

Try this...

UPDATE u SET 
	u.UserGroupId = 44
FROM
	dbo.tblUser u
WHERE 
	u.UserGroupId = 9
	AND u.UserName = 'TestPaul';