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 |
|
BLURDY
Starting Member
5 Posts |
Posted - 2010-02-09 : 12:47:32
|
| If I have 2 tables and I do 3 select statments ie Select * from a join (Select * from a) a1 ona.number=a1.number join (Select * from b)b1ON a.number = b1.numberThis will return 3 table which is fine.However how would I go about doing an update on thisupdate aset a1.test=a.testwhere etc |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-09 : 12:51:26
|
| Replace the initial SELECT * withUPDATE ASET ..."A" needs to be an alias to a table that is the FROM clause or a JOIN - it cannot be a derived table - so would be fine in your example |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-09 : 12:54:31
|
| [code]update aset a.test=a1.testfrom a join b a1on a.number = a1.numberwhere....[/code] |
 |
|
|
BLURDY
Starting Member
5 Posts |
Posted - 2010-02-09 : 12:56:53
|
| that didn workdoes anyone have 2 full tables they can throw up and we can go through this |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-09 : 13:02:19
|
quote: Originally posted by BLURDY that didn workdoes anyone have 2 full tables they can throw up and we can go through this
can you clearly state what your actual scenario is with some sample data? |
 |
|
|
BLURDY
Starting Member
5 Posts |
Posted - 2010-02-10 : 13:06:41
|
| tableasize,code,details10,1234,good20,5678,badtablebsize,code,details,bestbefore,cost10,1234,good,2010,0.0010,1234,good,2011,10.0020,5678,bad,2010,0.0020,5678,bad,2011,10.00if table a has the default value with no costs how can i change this around so it takes the ones with costi hope this is explained ok |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-10 : 13:09:06
|
quote: Originally posted by BLURDY tableasize,code,details10,1234,good20,5678,badtablebsize,code,details,bestbefore,cost10,1234,good,2010,0.0010,1234,good,2011,10.0020,5678,bad,2010,0.0020,5678,bad,2011,10.00if table a has the default value with no costs how can i change this around so it takes the ones with costi hope this is explained ok
Nope not quite oktablea doesnt have cost column. Hence I'm not sure what you mean by words in green above------------------------------------------------------------------------------------------------------SQL Server MVP |
 |
|
|
BLURDY
Starting Member
5 Posts |
Posted - 2010-02-10 : 13:14:44
|
| what i mean is that cost is not in table a but only in table b,but if i wanted to change the information around how would i do this |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-10 : 13:17:35
|
quote: Originally posted by BLURDY what i mean is that cost is not in table a but only in table b,but if i wanted to change the information around how would i do this
what info you want to change around?can you illustrate with some sample data as per below formathttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|