|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to restore Values to Table based on some QueryI have a table called A and another Table Called B. A table has the following Column and Values ID One Two Three ---------------------------------------------- 10 test01 test02 test03 11 test11 test12 test13 12 test21 test22 test23 13 test31 test32 test33 B table has the following Column and Values ID One Two Three ---------------------------------------------- 10 abcd01 abcd02 abcd03 11 abcd11 abcd12 abcd13 12 abcd21 abcd22 13 abcd31 abcd32 abcd33 I want to take a backup of Column Three where ID in(11,12,13). I know using BCP utility i can take a backup of Table A of Column Three. Following is the Query "select Three,ID from [Test].dbo.A where ID in(11,12,13)" queryout c:\try.txt -U sa -P *** and then i want to restore it in to the Table B's Column Three by specifying some Query. Meaning i want to restore the values to the Table B's Column Three where ID is the ID which is obtained in Backup[Table A]. How can i do this? If anybody knows the solution Please Let me know to solve it. Thanks, Vinoth Vin***@gsdindia.com Hi
I am not totally sure what you require, as it sounds like a simple update statement would do what you require e.g. UPDATE B SET [Three] = A.[Three] FROM TABLEB B JOIN TABLEA A ON A.id = B.id and B.id in ( 11, 12, 13 ) If you do choose to BCP the data out then your would probably need to load the data into a staging table. You may want to show what the final states of table a and b are. John Show quote "vin***@gsdindia.com" wrote: > Hi, > > > I have a table called A and another Table Called B. > > > A table has the following Column and Values > > > ID One Two Three > ---------------------------------------------- > 10 test01 test02 test03 > 11 test11 test12 test13 > 12 test21 test22 test23 > 13 test31 test32 test33 > > > B table has the following Column and Values > > > ID One Two Three > ---------------------------------------------- > 10 abcd01 abcd02 abcd03 > 11 abcd11 abcd12 abcd13 > 12 abcd21 abcd22 > 13 abcd31 abcd32 abcd33 > > > I want to take a backup of Column Three where ID in(11,12,13). I know > > using BCP utility i can take a backup of Table A of Column Three. > Following is the Query > > > "select Three,ID from [Test].dbo.A where ID in(11,12,13)" queryout > c:\try.txt -U sa -P *** > > > and then i want to restore it in to the Table B's Column Three by > specifying some Query. Meaning i want to restore the values to the > Table B's Column Three where ID is the ID which is obtained in > Backup[Table A]. How can i do this? If anybody knows the solution > Please Let me know to solve it. > > > Thanks, > Vinoth > Vin***@gsdindia.com > > |
|||||||||||||||||||||||