How can I update multiple values in 1 table based on the values from another table, do i need to use cursor ? or any loop ? every time there may be different values in temptable or sometime there may be no values at all. in this particular example there are three columns for which I need to update the values in temptable2from temptable1 i.e Name, Phone and AddressI know when updating we need to give field names and field values however in this case this will be coming from another table at runtime. Can I use any loop to execute Update dbo.temptable set ColumnValue = val1 where ColumnName = val2
For you to see what I have please use following codedrop table #temptable Create Table #temptable ( id int not null primary key, val1 varchar(50), val2 varchar(50))insert into #temptable(id,val1,val2) values(1,'Name','John'),(2,'Phone','1111111'),(3,'Address','Newton Australia')select * from #temptabledrop table #temptable2 Create Table #temptable2 ( columnname varchar(50), columnvalue varchar(50))insert into #temptable2(columnname) values('Address'),('idnumber'),('Phone'),('OfficeNumber'),('Surname')select * from #temptable2
Umar Memon