Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Need Help In Query . Expand / Collapse
Author
Message
Posted Tuesday, September 11, 2012 11:52 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 5:54 AM
Points: 172, Visits: 450
Could you please help me find records described as per below scenario.



Campus
code,address,CampusID(PK)
Data:-
DEL,ABC,1
CHN,DDJ,2
MUM,PQR,3
BNG,WRT,4
PUN,BNM,5

Enroll
StudId,CampusID,EnrollDate,LstAttendDate,Enrolid(PK)
1,2,15-06-2012,NULL,1001
1,5,31-05-2011,31-05-201,1002


ChangeStatus
StudId,Enrolid,NewStatId,PrevStatId,ChangeID(PK)
1,1001,1,0,5001
1,1001,2,1,5002
1,1001,3,2,5003

StatusMast
StatId Description
1,Active
2,Present
3,External etc.

In the above table resticted StatId are below.7,9,11,13 and 15.and rest are Active status.



Studunt can change campus or course any time.(course refers Enrolid).

Now i want to fetch studunt's old campus and new campus (Refer Campus Table) on below conditions.

1) students who went Active at Transferred From Campus before or after any of the restricted Statuses listed above in StatusMast table(i.e.StatId are - 7,9,11,13 and 15)
2)students who had an Active status at any time before or after any of the restricted Statuses at the Transferred To Campus
3)Students who’s Previous Status was Active and the corresponding New Status is in the restricted Status list at either the Transferred From Campus or the Transferred To Campus


Thanks
Abhas.
Post #1357795
Posted Wednesday, September 12, 2012 3:15 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, April 03, 2014 10:10 AM
Points: 2,792, Visits: 4,874
Looks like homework to me...
What have you tried so far?


_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1357852
Posted Wednesday, September 12, 2012 8:28 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, January 15, 2013 11:11 AM
Points: 1,945, Visits: 2,782
Where is the DDL? Why did you fail to use ISO-8601 date formats? There is no such thing as a “status_id” in RDBMS; you can have a “<something>_status” or a “<something>_id” but never a string of adjectives looking for a noun. Likewise, the term “_master” comes from network databases and magnetic tape file systems. Where is the DRI?

CREATE TABLE Campuses
(campus_id INTEGER NOT NULL PRIMARY KEY,
campus_name VARCHAR(35) NOT NULL,
campus_address VARCHAR(35) NOT NULL);

Was that so hard to do? You are doing the status changes wrong. Plese read http://www.simple-talk.com/sql/t-sql-programming/state-transition-constraints/ and make corrections.


CREATE TABLE Enrollment
(student_id INTEGER NOT NULL,
campus_id INTEGER NOT NULL
REFERENCES Campuses (campus_id),
enrollment_date DATE DEFAULT CURRENT_TIMESTAMP NOT NULL,
previous_enroll_status CHAR(8) NOT NULL,
current_enroll_status CHAR(8) NOT NULL,
CONSTRAINT Improper_Enrollment_Change
FOREIGN KEY (previous_enroll_status, current_enroll_status)
REFERENCES Status_Changes (previous_enroll_status, current_enroll_status),
..);

CREATE TABLE Status_Changes
(previous_enroll_status VARCHAR(10) NOT NULL
CHECK (previous_enroll_status IN
('Active', 'Present', 'External', .. )),
current_enroll_status VARCHAR(10) NOT NULL
CHECK (current_enroll_status IN
('Active', 'Present', 'External', .. )) ,
PRIMARY KEY (previous_enroll_status, current_enroll_status),
..);
Now fill out this table with the correct transitions.


Your queries are now easy, with the previous and current status codes.


Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Post #1358299
Posted Wednesday, September 12, 2012 10:55 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 5:54 AM
Points: 172, Visits: 450
Thanks CELKO.

I will try this one.

Thanks
Abhas
Post #1358337
Posted Monday, September 17, 2012 2:31 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 5:54 AM
Points: 172, Visits: 450
Still not tried anything as busy on other task.
If u have any idea in the mind then pls share.
Post #1360025
Posted Monday, September 17, 2012 2:47 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, April 17, 2014 9:33 AM
Points: 6,754, Visits: 12,854
abhas (9/17/2012)
Still not tried anything as busy on other task.
If u have any idea in the mind then pls share.


It's a simple assignment. What have you tried so far?


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1360030
Posted Tuesday, September 18, 2012 12:16 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 5:54 AM
Points: 172, Visits: 450
Hi Chris,
I tried using CTE but not able to do.
Post #1360575
Posted Tuesday, September 18, 2012 12:51 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 4:27 AM
Points: 398, Visits: 617
abhas (9/18/2012)
Hi Chris,
I tried using CTE but not able to do.


Please post your query.


--rhythmk
------------------------------------------------------------------
To post your question use below link

http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1360582
Posted Tuesday, September 18, 2012 2:13 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, April 17, 2014 9:33 AM
Points: 6,754, Visits: 12,854
abhas (9/18/2012)
Hi Chris,
I tried using CTE but not able to do.


No problem - post what you have, we'll help you make it work.


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1360612
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse