| Author |
Topic |
|
Leo_Don
Starting Member
42 Posts |
Posted - 2008-11-03 : 09:39:05
|
| Hi friends I cant execte the following Qurery.. can yo let me know what the error i am makingupdate dbo.@TESTTABLE set code = dbo.table1.CODEThanx |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 09:42:58
|
| [code]update t1set t1.code = t2.CODEFROM @TESTTABLE t1INNER JOIN dbo.table1 t2ON t1.linkingfield=t2.linkingfield[/code]replace linking field with actual fieldnamesEDIT: removed owner name from table variable as per Madhi's comments |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-03 : 09:43:35
|
| update t1set code = t2.CODE from @TESTTABLE as t1 inner join dbo.table1 as t2on t1.key_column=t2.key_columnMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-03 : 09:44:04
|
MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-03 : 09:45:25
|
quote: Originally posted by visakh16
update t1set t1.code = t2.CODEFROM dbo.@TESTTABLE t1INNER JOIN dbo.table1 t2ON t1.linkingfield=t2.linkingfield replace linking field with actual fieldnames
Not possible to qualify object owner for table variableMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 09:49:05
|
ah..good catch...didnt notice its a table variable post edited. |
 |
|
|
Leo_Don
Starting Member
42 Posts |
Posted - 2008-11-03 : 09:52:13
|
| i am getting this errorThe "@TESTTABLE" table variable must be declared |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 09:53:57
|
quote: Originally posted by Leo_Don i am getting this errorThe "@TESTTABLE" table variable must be declared
where you've declared the table variable. you need to make sure you run declaration along with above query in same batch as table variable will be out of scope only you ends a batch. show your full query batch if you need more help. |
 |
|
|
Leo_Don
Starting Member
42 Posts |
Posted - 2008-11-03 : 10:04:08
|
quote: Originally posted by visakh16
quote: Originally posted by Leo_Don i am getting this errorThe "@TESTTABLE" table variable must be declared
where you've declared the table variable. you need to make sure you run declaration along with above query in same batch as table variable will be out of scope only you ends a batch. show your full query batch if you need more help.
It Say O Colums Effected |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 10:06:11
|
| do you have enough data in both the tables which are related on the specified columns? |
 |
|
|
Leo_Don
Starting Member
42 Posts |
Posted - 2008-11-03 : 10:11:45
|
| I have data in table1below is the sampleTable1Code-------1234testtablecode------in the test table i dont have any data...all the colums are nullI want to copy the code from table1 to testtable |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 10:20:35
|
then it should be insert not updateinsert into testtable (code)select code from Table1 |
 |
|
|
|