?
Solved

Data to new table

Posted on 2010-01-11
4
Medium Priority
?
215 Views
Last Modified: 2012-05-08
I have
Table1  T1Id, T2Id,  T1Text, T1Password,T3Id
Table2  T2Id, T2Text.
I add another table i.e. empty table.
Table3   T3Id, T3Text,Password
I want to create a new row in Table3 for each row in Table1.
I want to update the column T3Id in Table1 with the T3Id of the new row in Table3.
I want also to set Table3.Password=Table1.T1Password and Table3.T3Text=Table1.T1Text
How is best to do this?
0
Comment
Question by:johnkainn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 30

Accepted Solution

by:
Reza Rad earned 500 total points
ID: 26283798
is the T3Id as identity field?
is there any other unique key in table3 ?


0
 
LVL 8

Assisted Solution

by:vinurajr
vinurajr earned 500 total points
ID: 26283802
Insert the Required data in Table3
Hope T3Id is a auto generating..?
then Update the data in Table1 with Table3

0
 
LVL 7

Assisted Solution

by:waltersnowslinarnold
waltersnowslinarnold earned 500 total points
ID: 26283843
Create a Stored Procedure,

CREATE PROC usp_ProcedureName
AS

INSERT INTO Table3 (T3Text, Password) (SELECT T1Text, T1Password FROM Table1)
DECLARE @id INT
SET @id = SELECT TOP 1 T3Id FROM Table3 ORDER BY DESC
UPDATE Table1
SET T3Id = @id
WHERE T1Password IN (SELECT Password FROM Table3)
go
0
 
LVL 15

Assisted Solution

by:David L. Hansen
David L. Hansen earned 500 total points
ID: 26283850
You could create a trigger to do this after you've created Table3.

See:
http://www.sqlteam.com/article/an-introduction-to-triggers-part-i
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question