Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Thursday, March 8, 2012

compare data

I've created two tables. One table (Classes) stores data about classes
that we offer. The Classes table stores the class id (classid) and the
max number of students allows (maxstudents). The other table
(Students) stores student data and the class they register for.

When a user registers for a class, the classid column data from Classes
populates the class column in Students.

I'm not sure how to count the number of students who registered for
course X, subtract that from the max number of students in the Classes
table, and display that the class if the max is reached either in a
warning dialog box or as text on the page.

I'm also populating a drop-down field on the registration form with the
class information from Classes. Confused yet?

I don't know much about SQL or .ASP. Any help is appreciated.> When a user registers for a class, the classid column data from
Classes
> populates the class column in Students

That seems strange. Don't you want to allow a student to take more than
one class? I would have expected a joining table to implement a
many-to-many relationship:

CREATE TABLE StudentClasses (student_id INTEGER NOT NULL REFERENCES
Students (student_id), class_id INTEGER NOT NULL REFERENCES Classes
(class_id), PRIMARY KEY (student_id,class_id))

Try this for your query:

SELECT C.class_id,
C.maxstudents - COUNT(S.class_id)
FROM Classes AS C
LEFT JOIN Students AS S
ON C.class_id = S.class_id
GROUP BY C.class_id, C.maxstudents

--
David Portas
SQL Server MVP
--|||Your design is wrong. Students do not have a class attribute; you need
enrollment for many classes.

CREATE TABLE Students
(stud_id INTEGER NOT NULL PRIMARY KEY,
...);

CREATE TABLE Classes
(class_id INTEGER NOT NULL PRIMARY KEY,
room_size INTEGER NOT NULL,
..);

CREATE TABLE Enrollment
(stud_id INTEGER NOT NULL,
class_id INTEGER NOT NULL,
PRIMARY KEY (stud_id, class_id),
...);

>> count the number of students who registered for course X, subtract
that from the max number of students in the Classes table,<<

SELECT E1.class_id,
(SELECT room_size
FROM Classes AS C1
WHERE C1.class_id = E1.class_id)
- COUNT(E1.student_id) AS available_seats
FROM Enrollment AS E1
GROUP BY E1.class_id;

Friday, February 24, 2012

Communication betwee two tables

Hai,

I am having a query that i want to communicate two tables that
one is school table & other is class table as shown below

school table:
Class strength
LKG 30
UKG 40

class table:(LKG)

Rollno name
1 rohit
2 baba

Now my query is that as i defined strength of the LKG class as 30, if
i insert 31st in to LKG i need to get error, that not to enter. That
implies that when i am going to enter 31 student in LKG table it should
not accept asthe data corresponding to the school table.Is it possible,
if it say the coding, as i am new to SQL plz help me in coding.

thanks,
lucky.lucky (j.v.s.s.baba@.gmail.com) writes:
> I am having a query that i want to communicate two tables that
> one is school table & other is class table as shown below
>
> school table:
> Class strength
> LKG 30
> UKG 40
>
> class table:(LKG)
>
> Rollno name
> 1 rohit
> 2 baba
> Now my query is that as i defined strength of the LKG class as 30, if
> i insert 31st in to LKG i need to get error, that not to enter. That
> implies that when i am going to enter 31 student in LKG table it should
> not accept asthe data corresponding to the school table.Is it possible,
> if it say the coding, as i am new to SQL plz help me in coding.

Wait here, you are saying that you have one table LKG, one table UKG etc?
That is not a correct design. Rather you should have a table classes
with a primary key (classcode, rollno).

Once there, you can have a trigger on the classes table:

CREATE TRIGGER class_tri ON classes FOR INSERT, UPDATE AS
IF EXISTS (SELECT *
FROM school s
JOIN (SELECT c.classcode, cnt = COUNT(*)
FROM classes c
WHERE EXISTS (SELECT *
FROM inserted i
WHERE i.classcode = c.classcode)) AS c
ON s.class = c.classcode
WHERE c.cnt > s.strength)
BEGIN
ROLLBACK TRANSACTION
RAISERROR('One or more classes are over-booked.', 16, 1)
RETURN
END

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||homework.

Thursday, February 16, 2012

Commented Dynamic Properties -- SQL2000 to SQL2005 mgration

Hi,
After DTS Migration is "successful", I opened up dynamic properties step but I saw codes were all commented out inside the public class ScriptMain. Since I am not familiar with Microsoft.SqlServer.Dts.Runtime, I'm not sure what methods I should use as there aren't much examples available online. How do I do the following in SISS way?

' Source(Type = 2)
' Global variable = SPLastDate
' Destination = 'Tasks';'DTSTask_DTSExecuteSQLTask_7';'Properties';'SQLStatement'

How can i convert this code for ssis ?
Does anyone have any solution ? kind of urgency.. Sad

Thanks
YaseminYou'd have to use property expressions instead - there is no automatic conversion for Dynamic properties task from DTS 2000.