How to Fetch specific no of rows dynamically from a Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NASEER337
    New Member
    • Apr 2015
    • 2

    How to Fetch specific no of rows dynamically from a Table

    i got this question in an interview!

    lats say i have a below table and i want to fetch the rows only till the period is currently active (all the rows above including Active Period = 1). if Active Period = 1 that means it currently Active.Query has to be dynamic lets say if the Active Period changes later then it has to fetch the rows till that period.

    YEAR DETAILS ACTIVE PERIOD
    2015 ONE 0
    2015 TWO 0
    2015 THREE 0
    2015 FOUR 1
    2015 FIVE 0
    2015 SIX 0
    2015 SEVEN 0
    2015 EIGHT 0
    2015 NINE 0
    2015 TEN 0
    2015 ELEVEN 0
    2015 TWELVE 0
    Last edited by NASEER337; Apr 14 '15, 12:30 PM. Reason: NOT SHOWING AS I AWNTED
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    What have you done so far?

    ~ CK

    Comment

    • NASEER337
      New Member
      • Apr 2015
      • 2

      #3
      i have tried by declaring 2 variables, using them in a while loop with the cursor But its not working. I am new here, i really dont how to get the answer, if anybody can help that will be great
      Last edited by NASEER337; Apr 14 '15, 05:43 PM. Reason: Mistake

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        Post what you have so far. A straightforward WHERE clause using a variable should do, unless I'm missing something. Based on the sample data you post earlier, can you post your desired output as well?


        ~~ CK

        Comment

        Working...