Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help Writing a Dynamic query

Author  Topic 

xrum
Yak Posting Veteran

87 Posts

Posted - 2010-04-23 : 15:10:35
i need to update one of the columns with something like "ID=[PersonID]"

is there a way to pull PersonID from that row, and update all columns at once with the that row's corresponding id?

so for example.

row one would be
personID = 1
update link column with + "ID=1"

row two would be
personID = 2
update link column with + "ID=2"

etc... thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-23 : 15:17:33
sorry didnt understand. can you provide a data sample?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

xrum
Yak Posting Veteran

87 Posts

Posted - 2010-04-23 : 15:29:21
hm... lets say i have 3 columns

userID --- Name --- Link
12 "Bob" "goto=12"
23 "John" "goto=23"
34 "Mary" "goto=34"
45 "Kate" "goto=45"

so, right now i already have the ID and the Name populated.

I need to run a query to insert values into column "Link". The new values will be "goto=" + [userID]

does that make sense?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-23 : 15:32:14
yup use

UPDATE Table
SET Link = 'goto=' + CAST(userID AS varchar(10))


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-04-23 : 15:32:46
Maybe this:

UPDATE table_name
SET Link = 'goto=' + CAST(userID AS VARHCAR(20))
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-04-23 : 15:34:33
Go to Top of Page

xrum
Yak Posting Veteran

87 Posts

Posted - 2010-04-23 : 15:38:08
Ahh! That worked! thanks! much easier then i expected :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-23 : 15:45:17
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -