Groups | Blog | Home
all groups > sql server programming > july 2007 >

sql server programming : Update with a select statement.


xyb
7/16/2007 7:48:24 PM
[quoted text, click to view]

update Profiles tt set USERNAME = t.USERNAME from
(
Select Upper(USERNAME) , ProfileName, Company, Division, Region,
Territory, 0,
'HOffice' , 1 FROM Profiles WHERE UserName = 'user_FirstName.
user_lastn...@COMPANY.COM' AND ProfileName = 'New Orleans North-396'
) as t
where tt.user1_lastn...@COMPANY.COM' AND tt.ProfileName =
Washington-396'
zwieback89
7/16/2007 11:16:37 PM
Hi,

The following select statement gets the values from the Profiles table.

Select Upper(USERNAME) , ProfileName, Company, Division, Region, Territory, 0,
'HOffice' , 1 FROM Profiles WHERE UserName = 'user_FirstName.
user_lastname@COMPANY.COM' AND ProfileName = 'New Orleans North-396'

I already have a record in the Profiles

Select Upper(USERNAME) , ProfileName, Company, Division, Region, Territory, 0,
'HOffice' , 1 FROM Profiles WHERE UserName = 'user1_FirstName.
user1_lastname@COMPANY.COM' AND ProfileName = Washington-396'

Now I want to update the the record for user1_FirstName.
user1_LastName@Company.com with the details of User_FirstName.
user_lastname@company.com

How can I do so?

THanks.

--
---------------------
zwieback89

Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/200707/1
M A Srinivas
7/16/2007 11:58:36 PM
[quoted text, click to view]

Assuming there is single record for each where condition

update a set
user1_FirstName = User_FirstName
from profiles a, profiles b
WHERE a.UserName = 'user1_FirstName.
user1_lastn...@COMPANY.COM' AND a.ProfileName = Washington-396'
and b.UserName = 'user_FirstName.
user_lastn...@COMPANY.COM' AND b.ProfileName = 'New Orleans
North-396'


AddThis Social Bookmark Button