Need Help In Query .

  • 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.

  • 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!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Thanks CELKO.

    I will try this one.

    Thanks

    Abhas

  • Still not tried anything as busy on other task.

    If u have any idea in the mind then pls share.

  • 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

  • Hi Chris,

    I tried using CTE but not able to do.

  • 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

    https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
    🙂

  • 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

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply