?
Solved

get to values and add them toghter then update the value

Posted on 2005-04-27
2
Medium Priority
?
169 Views
Last Modified: 2010-03-19
I have a problem that i cant work out how to get around, If a users name changes for what ever reason i need to get the value from the table PCM for OLD_NAME and then add it to NEW_NAME and then update the value of NEW_NAME to the new value


Each table will only have 1 record for each User, but their maybe be 20 differnt users that need this calculation of their old/new usernames points.

RENAME
--------------
OLD_NAME - VChar(20)
NEW_NAME - VChar(20)

PCM
--------------
NAME - VChar(20)
POINTS - Money

0
Comment
Question by:willa666
2 Comments
 
LVL 28

Assisted Solution

by:rafrancisco
rafrancisco earned 1000 total points
ID: 13878471
I think you will be needing an INSERT trigger in the Rename table:

INSERT INTO PCM (Name, Points)
SELECT A.New_Name, B.Points
FROM INSERTED A INNER JOIN PCM B
   ON A.Old_Name = B.Name

This will create a record in the PCM table using the new name and carrying over the balance from the old name.
0
 
LVL 10

Accepted Solution

by:
PSSUser earned 1000 total points
ID: 13878620
Or if the record already exists:
UPDATE PCM PCMNew
FROM PCM PCMOld INNER JOIN RENAME
     ON PCMOld.NAME=RENAME.OLD_NAME
SET POINTS=PCMNew.POINTS + PCMOld.POINTS
WHERE PCMNew.Name=RENAME.NEW_NAME
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question