vallury
asked on
Inserting Records into Temp table
Hello,
I have two tables Customer_Master and Student_Master as shown below
Customer_Master Student_Master
-------------------------- ---------- ---------- ------
Customer_ID Student_ID
First_Name Student_Fname
Last_Name STudent_LName
Customer_ID
One customer can have upto 3 students.
I want to create a temp table and insert records into this from the above 2 tables
The temp table should be like this
Customer_ID,First_name,Las t_Name,Stu dent_ID_1, Student_Fn ame_1,STud ent_LName_ 1,Student_ ID_2,Stude nt_Fname_2 ,STudent_L Name_2,Stu dent_ID_3, Student_Fn ame_3,STud ent_LName_ 3
Say if the Customer contains only 1 student record ,Student_ID_2,Student_Fnam e_2,STuden t_LName_2 and ,Student_ID_3,Student_Fnam e_3,STuden t_LName_3 should be null
Please help this is pretty urgent
I have two tables Customer_Master and Student_Master as shown below
Customer_Master Student_Master
--------------------------
Customer_ID Student_ID
First_Name Student_Fname
Last_Name STudent_LName
Customer_ID
One customer can have upto 3 students.
I want to create a temp table and insert records into this from the above 2 tables
The temp table should be like this
Customer_ID,First_name,Las
Say if the Customer contains only 1 student record ,Student_ID_2,Student_Fnam
Please help this is pretty urgent
To normalize the database, you can create a table which includes only the Customer_id and Student_id, plus a unique ID for that table. Then remove Customer_ID from the Student Table. Use a sql statement like the following example to view data :
SELECT
FROM (Customer_StudentData LEFT JOIN Customer_Master ON Customer_StudentData.Custo mer_ID = Customer_Master.Customer_I D) LEFT JOIN Student_Master ON Customer_StudentData.Stude nt_ID = Student_Master.Student_ID;
SELECT
FROM (Customer_StudentData LEFT JOIN Customer_Master ON Customer_StudentData.Custo
ASKER
Thanks for your response..
But what I want is to do is create a temp tbale
Declare @temptab table(
Customer_ID int,
First_name varchar(50),
Last_Name varchar50),
Student_ID_1 int,
Student_Fname_1 varchar(50),
STudent_LName_1 varchar(50),
Student_ID_2 int,
Student_Fname_2 varchar(50),
STudent_LName_2 varchar(50),
Student_ID_3 int,
Student_Fname_3 varchar(50),
STudent_LName_3 varchar(50)
and insert records from
Customer_Master Student_Master
-------------------------- ---------- ---------- ------
Customer_ID Student_ID
First_Name Student_Fname
Last_Name STudent_LName
Customer_ID
How do I insert records from the above tables into my temp table.
Thanks
)
But what I want is to do is create a temp tbale
Declare @temptab table(
Customer_ID int,
First_name varchar(50),
Last_Name varchar50),
Student_ID_1 int,
Student_Fname_1 varchar(50),
STudent_LName_1 varchar(50),
Student_ID_2 int,
Student_Fname_2 varchar(50),
STudent_LName_2 varchar(50),
Student_ID_3 int,
Student_Fname_3 varchar(50),
STudent_LName_3 varchar(50)
and insert records from
Customer_Master Student_Master
--------------------------
Customer_ID Student_ID
First_Name Student_Fname
Last_Name STudent_LName
Customer_ID
How do I insert records from the above tables into my temp table.
Thanks
)
Maybe it would help me if I knew what the end result of this temp table is? Are you looking for a report?
ASKER
@temp table once the records are inserted will like like something below and I am using the same in one of my reports
Customer_ID,First_name,Las t_Name,Stu dent_ID_1, Student_Fn ame_1,STud ent_LName_ 1,Student_ ID_2,Stude nt_Fname_2 ,STudent_L Name_2,Stu dent_ID_3, Student_Fn ame_3,STud ent_LName_ 3
1 John Kim 1 JBC LK 2 KKC PK 3 CCC FK
2 BB CC 5 KK FF Null NUll Null NUll Null null
and so on.
thanks again
Customer_ID,First_name,Las
1 John Kim 1 JBC LK 2 KKC PK 3 CCC FK
2 BB CC 5 KK FF Null NUll Null NUll Null null
and so on.
thanks again
ASKER
Experts,
Please help this is very very critical
Please help this is very very critical
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help bnrtech but this is not actually what I need.
But thanks again
But thanks again
@vallury - your table design is somwhat improper. If you have a definite no of studentsper customer then you should not be inserting them in a transaction style tyable.
If you can change your design, then this may just suit your better.
customer table:
Customer_ID, FirstName, Lastname, StudentID1, StudentID2, StudentID3
Student Table
StudentID
Firstname
Lastname
This design will prove much more efficient than your previous design.
Any comments?
If you can change your design, then this may just suit your better.
customer table:
Customer_ID, FirstName, Lastname, StudentID1, StudentID2, StudentID3
Student Table
StudentID
Firstname
Lastname
This design will prove much more efficient than your previous design.
Any comments?
ASKER
randeeps
Thanks for your response. The reason wny I am trying to do this is as follows.
I have a .aspx page in which there are form elements for Customer details and Student details. When a user clicks on lookup icon a new window will open and list of customers will be shown in that lookup window. Users when selected one Customer_ID from the lookup page based on the Customer_ID selected I need to populated the Customer details and Student details my ASPX page.
that is the reason why I want all the Customer and student details as one single record.
Thanks
Thanks for your response. The reason wny I am trying to do this is as follows.
I have a .aspx page in which there are form elements for Customer details and Student details. When a user clicks on lookup icon a new window will open and list of customers will be shown in that lookup window. Users when selected one Customer_ID from the lookup page based on the Customer_ID selected I need to populated the Customer details and Student details my ASPX page.
that is the reason why I want all the Customer and student details as one single record.
Thanks
I understand that Vallury.. what I would like to know is if the db is still in development stage then why dont you consider change of table design - a better and more efficient table design?
I am still here for a while ... let me know if this is possible. If not then will work on your solution.
Cheers!
I am still here for a while ... let me know if this is possible. If not then will work on your solution.
Cheers!
ASKER
Thanks randeeps.
the actual db design is excatly how you suggested. This new table is a temp table I am trying to create and populate records for my other usage.
the actual db design is excatly how you suggested. This new table is a temp table I am trying to create and populate records for my other usage.
in my design, the students are part of the customer table as Id fields. My design is totally different from yours. Pls check again.
The only solution using your design I can figure out is similar to @bnrtech... i.e. use of cursor. As he has mentioned, you have to loop thru the data and then inserting/updating the temp table. It is not a fancy solution but thats the bestwe can do in this design.
So please think it through and do consider this new design I have put forward.
Cheers
The only solution using your design I can figure out is similar to @bnrtech... i.e. use of cursor. As he has mentioned, you have to loop thru the data and then inserting/updating the temp table. It is not a fancy solution but thats the bestwe can do in this design.
So please think it through and do consider this new design I have put forward.
Cheers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
lludden and imran_fast and everyone.
thanks a ton for your help.
Thanks again
thanks a ton for your help.
Thanks again
ASKER