| Author |
Topic |
|
mailtosaja
Starting Member
28 Posts |
Posted - 2008-10-22 : 13:09:53
|
| Hi, see the below table. ID|Name|EmailID---------1|Null|null2|Null|null3|Null|nulli would like to update Name and EmailID column at a Time(single query).Is it possible?Thanks & Regards,S.WoodSon. |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-10-22 : 13:15:59
|
| yes |
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-10-22 : 13:16:16
|
| Do you have a reference column for the where clause ? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-22 : 13:17:21
|
yupUPDATE tSET t.Name=t2.namevalue,t.EmailID=t2.emailvalueFROM table tJOIN othertable t2on t.linkingcol=t2.linkingcol othertable is table from which you want to update. linking col are columns by which other table is related to your table. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-10-22 : 13:25:24
|
| If you don't have othertable and want to type in the desired data:update t1set [Name] = t2.[Name], EmailID=t2.EmailIDfrom table1 t1 -- this your TargetTableinner join(select 1 as ID, 'Mr. x' as [Name], 70 as EMailID union select 2, 'Mr. y', 71 union select 3, 'Mr. z', 72) t2on t1.ID = t2.IDWebfredNo, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
mailtosaja
Starting Member
28 Posts |
Posted - 2008-10-22 : 13:25:35
|
| Hi, thanks for your reply.I have only one table..Is it possible please send me the query..Thanks & Regards,S.Woodson. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-22 : 13:28:27
|
quote: Originally posted by mailtosaja Hi, thanks for your reply.I have only one table..Is it possible please send me the query..Thanks & Regards,S.Woodson.
then where will you get values from? |
 |
|
|
mailtosaja
Starting Member
28 Posts |
Posted - 2008-10-22 : 13:28:44
|
| Hi, Thanks for your reply.no. of Row changes that table...Thanks & Regards,S.WoodSon. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-10-22 : 13:35:36
|
quote: no. of Row changes that table...
don't know what that means.Was my solution not successful?My Test works:create table table1 (ID int, Name varchar(25), EMailID int)insert table1 select 1,null,nullinsert table1 select 2,null,nullinsert table1 select 3,null,nullselect * from table1update t1set [Name] = t2.[Name], EmailID=t2.EmailIDfrom table1 t1 -- this your TargetTableinner join(select 1 as ID, 'Mr. x' as [Name], 70 as EMailID union select 2, 'Mr. y', 71 union select 3, 'Mr. z', 72) t2on t1.ID = t2.IDselect * from table1drop table table1You have to adjust the right IDs of entries without Name and MailIdWebfredNo, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|