Transfer data from one Table to another T-sql

I need to transfer data from one table to another.
I will be using the SQL Query Analyzer to do this.

This is not a simple transfer of data to the same structured tables.
These tables are completely different, for the most part.

For instance, I will be selecting certain fields of one table.....

SELECT fldOne, fldTwo FROM someTable

I need to take this information, one row at a time and input it into a different type table.

So, something like this to insert into the other table...

INSERT INTO otherTable( fld1, fld2) VALUES( value1, value2 )

I've looked around for a sample to achieve this, but may have overlooked it?

Anyone have a link to show this or a quick sample?

Thanks all,

Zath


 

0
Zath
9/7/2005 8:25:17 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

3 Replies
626 Views

Similar Articles

[PageSpeed] 50

You can do a select from one table into another.

INSERT INTO otherTable( fld1, fld2
SELECT
   value1, value2
FROM
   someTable


bill
0
billrob458
9/7/2005 9:32:19 PM

Thanks for the feedback.  Finally remembered (very tired yesterday) I did something similar in a stored procedure and adapted that to fit my needs...

IF NOT EXISTS (SELECT user
  FROM users)
     BEGIN
         INSERT INTO newusers (user) VALUES (@userId) 
     END     
  

Zath

0
Zath
9/8/2005 1:12:51 PM
ooops, meant this one - LOL

INSERT INTO objScores (objID, studentID, courseID, objStatus)
     SELECT objID, @userID, @courseId, @objStatus
      FROM objStructure
     WHERE courseID = @courseId 

0
Zath
9/8/2005 1:30:05 PM
Reply:

Similar Artilces:

Transfering tables and data from one MS SQL DB to another MS SQL DB
I need to transfer tables and data from one SQL DB to another SQL DB. I know it can be done with Server Management Studio and I have searched Studio and Help but can't find any info on the database migration wizard. Hi,jayd  Follow This Link U can Get Help From This For Ur Case    http://forums.asp.net/t/1352620.aspx   PLZ MARK AS ANSWER IF IT HELP U. THANKS. RAGHAV MVP ASP/ASP.Net Read My Blog MARK THE POST AS ANSWER IF IT HELPS U. "Success doesn't come to you…you go to it."--Marva Collins "Success does not come to those who w...

is there an sql statement to insert data to one table and getting the data from another table
Ok I have a table that have general categories with just name and CatNo. Now what I want to know is when I create a client to move all the data in general categories to another table called categories that have the clientid to associate it with the client. I would appreciate for any help what is your question here??Shravan Addaypally MCP...

copying data from one sql table to another
I am trying to transfer data between two tables within the same database but am unsure how to do it. Also does any one know how to show all colums in a table except one without having to type out all the column names. Thanks You can transfer the data using a DTS package or via a script using insert into mytable select * from myothertable. You can only select all (*) or a specific list of colums (col1, col2, col3....).    Chuck Boyer, MCSD .NETDirector of Production and DevelopmentEdge Media Design insert into table1 (field names) select field names from table2.  Y...

Move a Table from one SQL 2005 Database to Another SQL 2005 Database
I created a table in an SQL 2005 database, however, I want to move that table and the data to another SQL 2005 database (within the same server). I am new to SQL 2005 and detailed instructions would be greatly appreciated. Thanks Bill You have two options the first is clean but the second is easier.  Try the links below for details.  Hope this helps. http://msdn2.microsoft.com/en-us/library/ms174335.aspx http://msdn2.microsoft.com/en-us/library/ms188029.aspx  Kind regards,Gift Peddie Thanks, but the documentations is somewhat overwhelming and was hoping of a ba...

Copying Binary data from one SQL table to another using XML
 Hi,     I have encrypted data stored as in binary format in a table .The data need to be copied into another table based on some conditions.I'm pasing the source table data to the SP in XML format. After inserted into the destination table , If I either try to compare both columns directly or after the decryption the values does not match.  I'm using ASP.Net2.0 with SQL server2005.The source table data is converted into XML document with   FOR XML PATH('employee'), ROOT('root'), BINARY BASE64 , ELEMENTS  and passed into SP...

Syntax to call a t-sql script from another t-sql script
I need to know how to call a t-sql script from another t-sql script. In Oracle I can add a line: @tce_load_company.sql to a sql command file, and it will run that file. This allows me to have a single "master" file that has all of my lower level table initialization values. What is the syntax for doing this in SQLServer? Thanks, Chris Emerson "Christopher A. Emerson" wrote: > I need to know how to call a t-sql script from another t-sql script. > > In Oracle I can add a line: @tce_load_company.sql to a sql command file, and it > will r...

Export sql table data into sql
 Dear friends ,   give any ideas for sql table data export into excel in asp.net c#   Hi  you can use import /export in sql server enterprise manager, other wise in c# you can bind  sql datas into gridview then convert into excel using following method  string filename = "ExcelFileName.xls"; HttpResponse response = HttpContext.Current.Response; // clean up the response.object response.Clear();response.Charset = ""; // set the response mime type for excelresponse.ContentType = "application/vnd.ms-excel"; response.Ad...

Wanting to take info from one SQL table and update to a seperate SQL table
Anyone have an idea of how I can take information from one table and edit it and insert into another SQL table.  I am using stored procedures and would like to continue to do so. Here is a copy of what I have so far:   <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="mp_Customers" SelectCommandType="StoredProcedure"></asp:SqlDataSource> </div> <h2><strong><font color="#C00000">Please enter a valid account number:</font></strong><...

Transferring Data from One Table to Another but add one more value
- INSERT INTO TABLE2 (COL1, COL2, COL3) SELECT COL1, COL4, COL7 FROM TABLE1 - what i want is i   INSERT INTO TABLE2 (COL1, COL2, COL3) SELECT COL4, COL7 FROM TABLE1 Username   (add one more value exp: Username) Just pass your values as parts of your select statement INSERT INTO TABLE2 (COL1, COL2, COL3) SELECT COL4, COL7,'Username' FROM TABLE1 Is it What you need? remember to use single quotes for strings, or you can also use variable Set @username ='Username'INSERT INTO TABLE2 (COL1, COL2, COL3) SELECT COL4, COL7,@Username FROM TABLE1 In both cases username will b...

boolean: {[If [table with this name] already exists in [this sql database] then [ don't create another one] else [create it and populate it with these values]}
the subject pretty much says it all, I want to be able to do the following in in VB.net code):   {[If [table with this name] already exists [in this sql database] then [ don't create another one] else [create it and populate it with these values]}   How would I do this?  run the below query, if it returns 1, table already exists. otherwise not exists. (select count(*) from sysobjects where xtype='u' and name = @name) Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever. Hello Sabrick, Can you try the following script...

How can i import records from a sql server table in project1 to another sql server table in project2
Hi, i have a table with all employee bio-data in a completed project. Iam now working on another project with a table that needs the same data and here iam talking about 300 records that rarely change. Instead of re-entering this data in this new table, i want to import the data from the completed project into a table in this new project. Does any one have any idea how to achieve that or is there a better option to do the same. One more thing iam realising here is that iam going to use this same data in very many applications and some one from one department is going to ...

Copy values from one table to another table using LINQ to SQL?
Hello,I have two database tables that have different names but identical structure (columns).What is the easiest way to copy the values from one table to the other table using LINQ to SQL? Thanks,-- shawn shawn Hi, As far as I research, we could use "foreach"  to insert the data from one table to another table. The code is shown below.         //there exist two table list and listSecond        DataClassesDataContext dataClass = new DataClassesDataContext(); //create the instance of the DataCon...

Updating a Table data from Another table using Sql Server 2000
Hi All, I have a Problem while updating one table data from another table's data using sql server 2000. I have 2 tables named TableA(PID,SID,MinForms) , TableB(PID,SID,MinForms) I need to update TableA with TableB's data using a single query that i have including in a stored procedure. use this type of query  update myTable2 set SID= (select top 1 SID from myTable1)Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever. u can use SELECT column_name(s) INTO newtable [IN externaldatabase] FROM sourcee.g.SELECT * INTO Persons_backup...

Submit Form to insert data into SQL and display with a gridview (edit as well) below how do i insert data into sql table?
I have an asp.net page that has a simple form where a user can submit customers information. Below that I have a gridview which displays customer information submited by the user who is logged in. I have the gridview displaying, sorting and updating as I want however I can't figure out how to bind a button click to insert data into the customer table and then have it refresh the gridview when they submit. Here is the basic code; (I am using AJAX for a calendar when a user wants to edit an appointment date) &lt;div class="leftBar"&gt; <div align=center&...