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.
Author |
Topic |
manish2aug
Starting Member
1 Post |
Posted - 2013-05-04 : 16:04:22
|
Hi, Can somebody please help me to solve a problem, I am new to sql .I have a table in which one column (Place) has some values like bellville, century city, constentia and ceres. Now in second table there are two columns property and value. Property column has values like population.rural.men.bellville.total, population.rural.men.constentia.total etc. Now I need to update the values of second table and iterate the first table to get the places. So in short like as followsFOR [column(index) in table_1]Beginupdate table_2 set value = 'someValue' where key ='population.rural.men.'+column(index)+'.total'ENDWhat will be the sql for this?ThanksManishmanish |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-05-05 : 21:14:30
|
quote: Originally posted by manish2aug Hi, Can somebody please help me to solve a problem, I am new to sql .I have a table in which one column (Place) has some values like bellville, century city, constentia and ceres. Now in second table there are two columns property and value. Property column has values like population.rural.men.bellville.total, population.rural.men.constentia.total etc. Now I need to update the values of second table and iterate the first table to get the places. So in short like as followsFOR [column(index) in table_1]Beginupdate table_2 set value = 'someValue' where key ='population.rural.men.'+column(index)+'.total'ENDWhat will be the sql for this?ThanksManishmanish
Where do you get the 'someValue' that you want to set the value column to? If that data is in a table, then you can do a set-based to query to do the update. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-06 : 02:17:21
|
sounds like this to meupdate t2 set value = 'someValue' from table_2 t2join table_1 t1on property ='population.rural.men.'+ LTRIM(RTRIM(t1.Place)) +'.total' As James suggested you could specify columnname instead of hardcoding if values reside in table column------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|