April 19, 2012 at 7:30 pm
Hey Guy please first don't care about my english.
I need somme explanation of you. I have one row like this in my table Infos.
Name | Level |
Stefan | 3 |
I want to udate level only a newLevel > level
update Infos set Level =(check (newLevel > level)) where Name = 'Stefan'
please how can i make a comparaison ??
April 19, 2012 at 7:54 pm
Is this what you are looking for?
CREATE TABLE #T(AName VARCHAR(10),ALevel INT)
INSERT INTO #T
SELECT 'Stefan',3 UNION ALL
SELECT 'Mike',2 UNION ALL
SELECT 'Samuel',4
SELECT AName,ALevel FROM #T -- check input
DECLARE @newlevel INT
DECLARE @oldlevel INT
SET @newlevel = 15
SET @oldlevel = 3
UPDATE #T
SET Alevel = @newlevel WHERE AName LIKE '%Stefan%' AND Alevel = @oldlevel
SELECT AName,ALevel FROM #T
Results:
AName Alevel
Stefan15
Mike2
Samuel4
A more generalized method:
DECLARE @newlevel INT
DECLARE @oldlevel INT
SET @newlevel = 15
SET @oldlevel = 3
UPDATE #T
SET Alevel = @newlevel WHERE Alevel = @oldlevel
SELECT AName,ALevel FROM #T --to check results
April 19, 2012 at 8:35 pm
I tunnel it little bittle the same But I want to Compare the Level of Stefan with Level of Samuel and Level of Mike . will i go to do the same as you has done??
April 20, 2012 at 6:37 am
My apologies, but I do not understand your request. Could you provide a sample of the results you are looking for ?
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply