Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 3rd, 2009, 05:40 AM
EliS EliS is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 2 EliS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 10 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old September 3rd, 2009, 05:48 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 3,632 sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Days 15 h 14 m 45 sec
Reputation Power: 1909
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?

Reply With Quote
  #3  
Old September 3rd, 2009, 06:06 AM
EliS EliS is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 2 EliS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 10 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old September 22nd, 2009, 07:33 PM
gregory.owen@hp gregory.owen@hp is offline
Maniac
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2003
Location: Sweet Home, Oregon
Posts: 598 gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 14 h 46 m 46 sec
Reputation Power: 37
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

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Stored Procedures - Updating many to many table from temp table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 9 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek