While loop return same record twice

I have script below returns 2nd row twice 
File ID: 2 File Location Drive : D:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MSDBLog.ldf
File ID: 2 File Location Drive : D:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MSDBLog.ldf
it should return result 
File ID: 1 File Location Drive : D:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MSDBData.mdf
File ID: 2 File Location Drive : D:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MSDBLog.ldf
Any idea whats wrong?
 DECLARE @dbdatafile2 VARCHAR(500), @fileid2 int, @i2 int;
 set @i2 = 1
 while (@i2 <= 2)
  begin 
  select  @fileid2 = file_id, @dbdatafile2 = physical_name from sys.master_files where database_id = 4;
    PRINT 'File ID: ' +( CONVERT(VARCHAR, @fileid2))+' File Location Drive : ' + @dbdatafile2 ;
 set @i2 = @i2 + 1
 end;
 GO

select  @fileid2 = file_id, @dbdatafile2 = physical_name from sys.master_files where database_id = 4;
If you query this way, you will always get the same (random) file_id; you have to change your query in this way (marked in bold):
set @i2 = 1
while (@i2 <= 2)
begin
select @fileid2 = file_id, @dbdatafile2 = physical_name
from sys.master_files
where database_id = 4
and file_id = @i2;
PRINT 'File ID: ' +( CONVERT(VARCHAR, @fileid2))+' File Location Drive : ' + @dbdatafile2 ;
set @i2 = @i2 + 1
end;
GO
Olaf Helper
[ Blog] [ Xing] [ MVP]

Similar Messages

  • FindByProperty Returns Same Record Twice

    I have a curious situation in which the findByProperty method is returning the same record twice. I have only two records in the file for this test, and they are both tied to the same contact ID. But, instead of bringing back both records, it brings back the first record twice. Any ideas?
    ContactNote entity
    @Entity
    @Table(name = "CONTNOTEP", schema = "CRMLIB", catalog = "S657567F", uniqueConstraints = {})
    public class ContactNote implements java.io.Serializable
         // Fields
         @Id
         @Column(name = "CONTACTID", unique = false, nullable = false, insertable = true, updatable = true, precision = 5, scale = 0)
         private Long                    contactId;
         @Temporal(TemporalType.DATE)
         @Column(name = "CNDATE", unique = false, nullable = false, insertable = true, updatable = true, length = 10)
         private Date                    lastUpdatedDate;
         @Temporal(TemporalType.TIME)
         @Column(name = "CNTIME", unique = false, nullable = false, insertable = true, updatable = true, length = 8)
         private Date                    lastUpdatedTime;
         @Column(name = "CNNOTE", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
         private String                    note;
         @Column(name = "CNSALMNUM", unique = false, nullable = false, insertable = true, updatable = true, length = 2)
         private String                    salesmanNumber;
         @ManyToOne(fetch = FetchType.LAZY, cascade = {})
         @JoinColumn(name = "CONTACTID", insertable = false, updatable = false)
         private Contact                    contact;
         @Transient
         private GregorianCalendar     date;
    ContactServiceImpl
         public List<ContactNote> getContactNotes(String sessionId, Long contactId) throws AuthenticationFault
              authenticateSession(sessionId);
              List<ContactNote> contactNoteList = contactNoteDao.findByProperty("contactId", contactId);
              if (contactNoteList.size() == 0)
                   ContactNote contactNote = new ContactNote();
                   contactNoteList.add(contactNote.defaultContactNote());
              return contactNoteList;
    JUnit Test Method
         @SuppressWarnings("unchecked")
         public void runGetContactNotes() throws Exception
              UserDao userDao = (UserDao) applicationContext.getBean("userDao");
              User user = userDao.login("[email protected]", "password");
              assertNotNull(user);
              ContactService dao = (ContactService) applicationContext.getBean("contactService");
              List<ContactNote> contactNoteList =
                   dao.getContactNotes(user.getSessionId(), 1276L);
              for (ContactNote note : contactNoteList)
                   System.out.println(note.getContactNoteId() + " " + note.getNote());
    Results of Test
    [TopLink Fine]: 2007.10.02 08:50:30.988--ClientSession(7339385)--Connection(6964063)--Thread(Thread[main,5,mai
    n])--SELECT CONTACTID, CNTIME, CNNOTE, CNDATE, CNSALMNUM FROM CRMLIB.CONTNOTEP WHERE (CONTACTID = CAST (? AS B
    IGINT ))
         bind => [1276]
    1276 Jason requested to get Sinclair gift card "backs" because they have so many returned/used gift cards
    1276 Jason requested to get Sinclair gift card "backs" because they have so many returned/used gift cardsThanks for any help that can be provided. This has me stumped.
    R. Grimes
    Message was edited by:
    rdgrimes

    I was able to resolve this situation by splitting the ContactNote entity in two: ContactNoteId and ContactNote. I had combined them because it seemed kind of silly to have the id, date, time in the ContactNoteID entity, while the ContactNote entity just had two fields beyond the embedded id.
    R. Grimes

  • How to structure a control and its display in the same while loop and same display panel (instead of display panel and a seperate parameter-setting panel )

    As you can see, I need to adjust the Target position to certain value (like 1068.88), the actual position is showing 1066.99.  What kind of flow control structure will achive this goal?
    Notice the Labview example "Vibration analysis"  may shed some light on this issue.  Will someone give out a simpler code to show how it works?
    Attachments:
    Spectrometer Control V3.0.vi ‏113 KB

    lightblue,
    Just to make sure we are on the same page, you would like to set the position, then monitor it.  Is that correct?  In that case, you might have a few options.  You could have a sequence that would set the position, and then a while loop that would monitor the position, however this wouldn't allow you to update anything else.  The other option would be to use parallel while loops, which would be similar to the parallel sequence structure you have below.  The only issue with this would be that if you are calling the driver from both loops, you could run into errors.  The Vibration Analysis.vi takes the setpoint, then calculates the actual available position, so it won't serve as a very good example, code-wise. 
    Hope this helps!
    Andy F.
    National Instruments

  • Why two remote keys are genrated in data manager when i'm syndicating the same records twice

    Hi Experts,
    Please guide me that will there be any problem if two remot keys are getting generated for the same system thougt we are expecting to update the same Business Partner Number in ECC.
    Also We are able to see two different business partner number(in ECC this is KUNNR in KNA1)
    Please guide me how to proceed so that when we syndicate the same set of records we want to get update the records in ECC for the same KUNNR.
    We don't want to get another KUNNR for the same records.
    Thanks!
    Pankaj

    "barbara" wrote in message
    news:506500000008000000FAC20000-1077587809000@exch​ange.ni.com...
    > I'm using the simulation interface toolkit V2.0 but it works only the
    > first time after the installation. When I restart again my computer it
    > doesn't work any more. Why??????????
    >
    ---snip
    I am not familiar with the different software that you mentioned but as a
    first step I would check compatibility which is done as below:
    Get original operating system CD that was used to install Windows XP on the
    machine in your post. When Windows XP is inserted into CD ROM drive it
    normally will ask you to conduct compatibility check for the current
    installation. See what it says.
    HTH
    Mohan Pawar
    ----snip

  • Error while using the same recording

    Hi All,
    I created a new recording and uploaded some data and it worked fine but when i use the same recording to upload the remaining data at the time of creating batch session in am getting an error " BDC_INSERT QUEUE AT. "
    Im fairly new to LSMW can anyone help me how to solve this.

    Hi
    Please check the data converted for upload and there may be some extra spaces which is causing the problem.
    Try to use a new file converted and upload it again.
    Shiva

  • Custom pll to disable form messages while looping through block records

    I need to loop through block records in CUSTOM pll to check for if one check box is checked or not. But in that process the messages written at the forn level are popping up which are of no use to the user. I want to disable the messages for my looping. I would enable it after the processing in CUSTOM PLL
    Regards,
    SS

    Hello,
    Here is the Forms forum, and you would increase chances to get an answer by posting in the EBS forum.
    Francois

  • Avoid Math.random() from looping the same number twice?

    I'm trying to play a random gallary image by making it stops at different frame every few seconds, and the actions is completely random.
    The problem is, since there are only 5 different images(5 frames) I'm displaying, there is a high probability that it stays at the same frame, how do I avoid that? Like avoid staying at the same page twice, if not run the function again....?
    setInterval(createItems,throwItems);
    var RandomImg:randomImg =new randomImg();
    RandomImg.y=100;
    RandomImg.x=180;
    RandomImg.gotoAndStop(Math.floor(Math.random()*(1+5-1))+1);//generate random value between 1-5
    addChild(RandomImg);
    Thanks

    How do I keep track of the random value, like what value should I put within the if to compare?
    I try modify it a little, and wrap it within an if(), and use preValue to track down the previous frame, am I doing it right?
    setInterval(createItems,throwItems);
    var preValue:Number;
    function createItems():void
         var RandomImg:randomImg =new randomImg();
         var randomFrame= Math.floor(Math.random()*(1+5-1))+1; //generate random value between 1-5
         RandomImg.y=100;
         RandomImg.x=180;
         RandomImg.gotoAndStop(randomFrame);
         if(preValue == randomFrame)
              RandomImg.gotoAndStop(Math.floor(Math.random()*(1+5-1))+1);
              addChild(RandomImg);
              preValue = randomFrame;
         }else
                        addChild(RandomImg);
                        preValue = randomFrame;

  • "Find Finder Items" returns same file twice

    Hey y'all,
    I'm trying to jerry-rig a photobooth for my wedding. I'm using automator to grab 3 stills from a webcam, and place them all in a folder. When I use "Find Finder Items" to send these images to an action that will rotate them, it finds one of the images twice. That is, the results for "Find Finder Items - where: path whose: name contains 'snap' " will return pictures/path/snap3.tiff, pictures/path/snap1.tiff, pictures/path/snap2.tiff, pictures/path/snap3.tiff. This means that when I send these results to my Rotate 90 Degrees action, Snap3 is rotated 180, and when I send them all into a PDF, I get snap3 twice.
    This also happens when I "Find Finder Items" and just look for all the .tiff files in /path, and when use "Get Folder Contents" on /path.
    Background: Running 10.5.8 Leopard on a PPC Mac mini. Fairly new to the world of Mac, so I may be missing something obvious.
    I've been searching for answers for a day or two now, and haven't come across this sort of issue; I apologize if this is old hat, but I really have made a goodfaith attempt to search these and other forums.
    Any help would be greatly appreciated.
    Edited to add: The folder only contains the 3 .tiff files, and the PDF I'm trying to dump them into. I thought maybe I was somehow creating a 4th identical file, but it's not the case.

    Hello & a warm welcome!
    no idea what is happening, other than Apple Software is usually the worst to accomplish thing the way YOU want to.
    GraphicConverter has a powerful Browse Folder function, & many tools for manipulation, & you can keep your Pics wherever you want...
    http://www.lemkesoft.com/

  • Help learning while/do while loops

    Hi everyone, glad to see there are resources out here like this where newbies with Java can get help and learn from the gurues!
    I am having a problem with constructing a while loop that is going to compute the sinx without using the Math.sin function....so given this
    sinx = x - (x^3/3!) + (x^5/5!) - (x^7/7!) + ......
    It seems I need to use the Math.pow function. So the sinx is alternating signs between each new set of parenthesis and the power and factorial are increasing by 2..starting with 3. I think this is were I am having my trouble.
    I was going to use a do-while loop for cosx which is
    cosx = x - (x^2/2!) + (x^4/4!) - (x^6/6!) + ......
    I think my problem is that I can't figure out how I would go about writing this. If I can get the sinx with the while loop, I can probably get the cos on a do-while statement since they are similar. I did get factorial(n) defined below.
    I have another main class which I am using to get the input of sin/cos x using computeSin and computeCos functions I am trying to build here.
    import javax.swing.*;
    public class NewMath
    public static double computeSin(double x)
    double result = x;
              // Going to use A WHILE LOOP
    return result;
         public static double computeCos(double x)
    double result = 1;
              // Going to use a DO-WHILE loop
    return result;
    private double factorial(int x) {
    if (x <= 1) return 1.0;
    else return x * factorial(x - 1);
    Any tibits of help would be nice. If I think I got it working before someone else posts, I'll post my results. Thanks.

    Any tibits of help would be nice. If I think I got
    it working before someone else posts, I'll post my
    results. Thanks.You already have your own tidbits, as you've observed the pattern of alternating adding/subtracting, as well as how the power and factorial factors relate. Any more "tidbits" here would just result in doing it for you, it seems. So get to it, and if you run into specific problems, you can ask.

  • While loop brings out of bounds error

    I cannot see why this while loop is bring the out of bounds errror in my program please let me know how to correct it
    thanx
    import java.util.Scanner;
    public class UniqueNumbers
         public int count3 = 0;
         public int count2 = 0;
         public int count = 0;
    public int number = 0;
    // public int ifnumber;
    public int arrayBuild()
         int numbers[]; // declare array named array
         numbers = new int[ 5 ]; // create the space for array
    Scanner input = new Scanner(System.in);
    //System.out.println("Enter a number between 10 and 100.");
    //int ifnumber = input.nextInt();
    while (count3 <=numbers.length)
    System.out.println("Enter a number between 10 and 100.");
    int ifnumber = input.nextInt();
              if (ifnumber >= 10 || ifnumber <= 100)
              numbers[count] = ifnumber;
                   count++;
                   count3++;
    if (ifnumber < 10 || ifnumber > 100)
    System.out.println("Number is out of range.");
              continue;
    //for(count2 = 0; count2 < numbers.length; count2++)
    // if(numbers[count] != ifnumber)
    // System.out.printf("%d\n",ifnumber);
    }//end while loop
    return numbers[count];
    }//end arrayBuild
    public void displayMessage()
         //display number inputted by user
              System.out.printf("The number you entered is: %d \n", getNumbers() );
    }//end displayMessage
    public int getNumbers( )
         number = arrayBuild();
         return number;
    }//end getNumbers
    }

    Do this instead:
    while (count3 <numbers.length)

  • Oracle query returns every expected record twice

    I have a query that at times could return a very large number of records, but I want to process them in blocks within a time budget, so I will process as many as I can within a time budget and then close the ResultSet. I looked at the two obvious ways to control how many rows I get back, using "ROWNUM <= N" and "setFetchSize()".
    I think the latter is the more common way of doing this, but I noticed that it's considered a "hint". I think it's likely it would always be used, but because of that small doubt I decided to try using the "ROWNUM <= N" strategy first.
    It seemed to be working fine, but I noticed an oddity where it was often returning all the relevant rows twice. I'd gotten the set of records to operate on down to a very small number (8), and I entered the query it uses directly into a SQL browser, and it returned the 8 records I expected. My query was using "ROWNUM <= 20". I stepped into the ResultSet "next()" loop, and I watched it process the 8 records, and then instead of returning "false" from the following call to "rs.next()", it returned true and started at the beginning of the 8 records again. It eventually processed all 8 records twice.
    So, I just tried changing it from using "ROWNUM" to using "setFetchSize()". The results were exactly the same. It still processed all 8 records twice.
    The query is very simple. It just looks like this, with most of the column names removed, and the table name changed:
    SELECT ID, ... FROM TABLE_NAME tn WHERE tn.CREATION_DATE = ?
    The somewhat elided code for the loop looks like this:
    try {
    rs = getRecords(connection);
    // Indicates whether at least one row was found.
    boolean foundOne = false;
    while (rs.next()) {
    foundOne = true;
    final Record record = makeRecord(rs);
    processRecord(record, counters);
    ++ recordsProcessed;
    if (!foundOne) {
    break;
    if (overTimeBudget(startTime)) {
    break;
    logInfo("Processed " + recordsProcessed + " record" +
    (recordsProcessed == 1 ? "" : "s") + " so far.");
    What could be going wrong here?

    Never mind. Dumb mistake. It wasn't an Oracle problem. I was doing the query inside a loop because of an earlier design decision.

  • Problem while looping through record set and tem table for matching data

    hi I am using one record set and ane temp table and looping through both to find the match between dates.
    If date matches then it shud do some processing otherwise it will return default values(null values).
    FOR i IN student_rec .FIRST..student_rec .LAST          /*student_rec.school_date has 01-MAR-2012,02-MAR-2012,03-MAR-2012,04-MAR-2012,05-MAR-2012*/
    LOOP
    l_return_out.school_date := student_rec(i).school_date;
    l_return_out.marks_obtained := student_rec(i).marks_obtained;
    FOR i IN selected_dates .FIRST..selected_dates .LAST          /*selected_dates has 02-MAR-2012,03-MAR-2012,05-MAR-2012*/
    LOOP
    DBMS_OUTPUT.PUT_LINE(selected_dates(i));
    IF selected_dates(i)=student_rec(i).sett_date
    THEN
    EXIT;
    end if;
         ---------call procedure P1
    -----------get output as ret_val1               /*getting ret_val1 as 10 for 02-MAR-2012,03-MAR-2012,05-MAR-2012 */
         ----------call procedure P2
    ---------get ouput as ret_val2               /*getting ret_val1 as 20 for 02-MAR-2012,03-MAR-2012,05-MAR-2012 */
    if ret_val1>0 0r ret_val2>0
    then
    l_return_out.has_csts := yes;
    l_return_out.cst_present := 10;
    l_return_out.cst_absent := 20;
    else
    l_return_out.has_csts :=No;
    l_return_out.cst_present:= 0;
    l_return_out.cst_absent := 0;
    end if;
    end loop;
    l_return_out.has_cst := student_rec(i).has_csts;
    l_return_out.cst_missing := student_rec(i).cst_present;
    l_return_out.cst_existing := student_rec(i).cst_absent;
    PIPE ROW(l_return_out);
    END LOOP;
    RETURN ;
    I am expecting this as result
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          yes 10          20
    03-MAR-2012     40           yes 10          20
    04-MAR-2012     70          
    05-MAR-2012     60          yes 10          20
    but this as result
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          
    03-MAR-2012     40           
    04-MAR-2012     70          
    05-MAR-2012     60          
    Can anybody please highlight the mistake i am doing while processing the logic??
    Edited by: 942390 on Jul 13, 2012 8:44 PM
    Edited by: 942390 on Jul 13, 2012 8:45 PM

    I am getting a set values from a record set....student_rec
    and on pipelining this record set from 1st till last
    i am getting this
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          
    03-MAR-2012     40           
    04-MAR-2012     70          
    05-MAR-2012     60     
    so initially has_csts, cst_present and cst_absent is null for all dates.
    now have a temp table of selected_dates(which contains these dates 02-MAR-2012,03-MAR-2012,05-MAR-2012)
    now I am want to populate has_csts, cst_present and cst_absent with data only for those dates which is present in selected_dates temp table(02-MAR-2012,03-MAR-2012,05-MAR-2012) and that too has_csts, cst_present and cst_absent will be populated with some condition (based on the values from procedure got from P1 and P2).
    so want result set to look like
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          yes 10          20
    03-MAR-2012     40           yes 10          20
    04-MAR-2012     70          
    05-MAR-2012     60          yes 10          20
    so what could be the possible solution to obtained this....

  • How do you plot multiple curves on the same graph when using a while loop?

    I am writing a program that will plot the IV Output chracterisitcs curves for a MOSFET transistor. I have two sweep variables Vg and Vd. For each Vg valve selected, Vd is swept from its start to stop voltage creating a graph for that Vg valve. Both of the sweeps are done using while loops. Ideally I would like to display all of the Vg plots on the same graph while having the ability to do real-time graphing. Can anyone help me figure this problem out? I have attached my program. Thanks!!
    Tammy
    Attachments:
    outputfin2.vi ‏165 KB

    Hi Tammy & Tica T,
    As far as I see it - this thread is a very bad version of already existing bad version......
    http://forums.ni.com/ni/board/message?board.id=170&message.id=127857
    I expected, that an Applications Engineer from NI knows something about  a Transistor and how an Output characteristic looks like !!  Take a look to a typical Transistor Datasheet ( e.g. n-channel MOSFET) - you will see, that there is no relation of ID vs Time like in your example ( values vs time )  but  IDrain vs VDrain at different VGate's ( no relation to Mr. Bill Gates ).
    Find attached a vi, that in general does what you need - drawing of  curves vs x-axis (XY-graph in use)  - in test_sweep.zip.  And that you geet an impression, how it might be done ...... dynamic Output characteristic of a Transistor with Standard Equipment of a Lab ( Scope + Generator + Power Supply ) find in addition a Frontpanel - picture. One of the interesting points here is - the self-heating effect; visible on ch3 of scope - 5µs Pulse is already a very long time...... This measurement was done in order to compare with our own Transistors......... 
    Hope this helps a little bit to understand, what we are talking about.
    Regards
    Werner
    Attachments:
    test_sweep.zip ‏358 KB
    dynamic Transistor char.png ‏65 KB

  • I currently have one input but need to run two loops. I cannot get the two while loops to run so that they both pick up the same data, they are both picking up alternate samples. How can I get them to both pick up all of the values?

    The system I am trying to create calculates a number of values based on an input. I need to make the calculations and display the values for an entire production run and for each hour. The only way I know to do this is to create two while loops, one looking at all the values that are received and one looking only at the values for hour long periods.
    Any help would be great.
    Thanks
    RossH

    Why do you think that you have to have two loops to accomplish this task? Why not use one loop and accumulate the same data into two data sets based on the two sets of criteria?

  • Program times out while looping at internal table with huge records - Needs fine tuning suggestions

    Hi,
    I am trying to execute a report. It times out while looping at vbap internal table. This internal table has 140000  records and does the validation within this loop and geenrates data for the output. Due to this huge volume, the program times out when executed foreground.
    There are no nested loops, so I cannot apply 'Parallel Cursor' here.
    Is there any way I can fine tune the program so that it doesn't timeout? Is it possible to apply 'Parallel Processing' . If yes, how?
    Thanks,
    Pavan

    Hi Pavan ,
                  ->sort your internal table by all primary key for vbap.
                  ->Read a Record from the table (use your condition here)
                  ->if record satisfys your where condition ,get that record index .
                  ->loop the table from the index (without condition) .
                  its like parallel cursor only but for single loop .;-)
                  ->use field symbols ,wherever possible .
               if still dump is coming ,contact your basis team .
    regards,
    Krishna.

Maybe you are looking for

  • Question about the cache

    So I never really worried or cleared the cache in the past year on this computer. I occasionally cleared the cookies from time to time, but I never let Firefox clear cache or cookies due to me wanting to have some passwords saved on some sites and au

  • Using function on decode or case in query

    Hi experts I am using oracle 11G database,I have to check length of name column value from employee table and if length(name) > 39 then value should be substr(name,0,39) else value should be name only. i tried below code select CASE when length(name)

  • VISACOM - Alloc Error using 488.2 USB-B Interface - too many open sessions

    I have been having the following issue in my VB .NET RF-ATE application.... It usually happens when my program enters a measurement loop (I.E. searching for P1dB). It begins to solve for P1dB and performs about 15 cycles (sets power level on SigGen a

  • Error Workflow Project Server 2013

    I have Sharepoint 2013 farm. In SPD 2013 create workflow Sharepoint 2013-Project Server. And want to write in workflow log Project UID. But in during i see error: System.ApplicationException: HTTP 403 {"Transfer-Encoding":["chunked"],"X-SharePointHea

  • ENCORE DVD2.0 can't decode MP3 file?

    It is probably my fault although I do not know what I did wrong: I have been importing assets, including MP3 files, into Encore DVD2.0 for a 'long' time without any problem. I 'truncated' and faded in/out one MP3 in PrE7 and exported it to a folder f