|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Stored Procedures - Updating many to many table from temp table
Hello,
I'm having a problem populating/altering many to many table with temp table I'm using. For this matter i use 4 tables: Table 1 - Coach's, Table 2 - Course Type, Table 3 - Courses of Coach's (many to many Table), Table 4 - tempCOC I'm using the tempCOC for the GUI, it includes all the Courses types with additional check box. So when a user UNcheck/check a box the db will be updated accordingly. The problem occurs when i want to send the data from the temp table to the 'Courses of Coach's' table according to check box being checked/unchecked. How do i update the table with the new data most efficiently? Thanks for the help, Eli. |
|
#2
|
||||
|
||||
|
Hi, and welcome to the forums.
I'm afraid I dont really understand the problem, would it be possible to see some sample data and any relevant code. Without really understanding the problem properly, the only suggestion I could make would be to delete all data from the [Courses of Coachs] table before reinstating it from the tempCOC table with the most recent data. I'm just really confused as to the purpose of the temp table? |
|
#3
|
|||
|
|||
|
Thanks for the quick reply.
Data: Coach's: CoachID: 111 fName:Eli lName: S CoachID: 222 fName:Mike lName: M Course Type: typeID:1 description:Boxing typeID:2 description:Karate Courses Of Coach's: COCid:1 CoachID: 111 typeID:2 COCid:2 CoachID: 111 typeID:1 COCid:2 CoachID: 222 typeID:1 TempCOC typeID:1 description:Boxing check:false typeID:2 description:Karate check:false The TempCOC is loaded for every coach now being updated, lets say I'm editing Mike Courses via GUI (ASP.NET) i want to c all the courses available and then check or uncheck the courses he can tutor. eventually update the Courses Of Coach's accordingly to the check box being checked or unchecked. I hope i explained it better this time Thanks again. |
|
#4
|
|||
|
|||
|
The tempCOC table is unnecessary--given a coach's ID number it can be built dynamically:
Code:
SELECT ct.typeID, Description, CASE ISNULL(COCid,0)>0 THEN 'True' ELSE 'False' END as [Check] FROM [Course Type] ct LEFT JOIN [Courses of Coaches] coc ON ct.typeID = coc.typeid WHERE coc.CoachID = 111 When a new check box is checked, use insert: Code:
INSERT INTO [Courses of Coaches] (CoachID, TypeID) VALUES (@CoachID, @TypeID) When you un-check, use delete: Code:
DELETE FROM [Courses of Coaches] WHERE coachID=@coachID AND TypeID = @TypeID |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Stored Procedures - Updating many to many table from temp table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|