Updating Running fields

  • Hey Guys Whats Up...

    Got some problem here about manipulating fields in a Query... sample;

    I have a 4 fields in a select Query...

    Select Given,Var1,Var2,Result from table1

    then the Result field in the first row thats the value in given field that im gonna use in the second row and so on...

    is there any function in SQL 2k that can solve this kind of problem...?

    Thanks A lot in Advance....

    DROP THE ZERO AND GIVE IT TO THE HERO...ZEROCOOL

  • Sounds like you will have to build a temp table that will be populated by the 1st row with whatever criteria is used to pull the data for the 1st row.

    THEN

    SET @Result = (SELECT Result from #tmpTable)

    BEGIN LOOP

    INSERT INTO #tmpTable

    SELECT Given, Var1, Var2, Result FROM table1 WHERE Criteria = @Result

    SET @Result = (SELECT Result FROM table1 WHERE Criteria = @Result)

    CONTINUE LOOP until done.

    This is just concept code and not operational.

     



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • A bigger sample of data would have  been clearer.

     

    I believe what you're wanting is :

    Select a, b, c, d from table

    1,23,34,56

    56,67,78,89

    89,90,32,23

    23,36,75,24

    Is that what you were talking about?  The fourth column value is the first column value in the next row.  Or for a more relevant example:

    November, testing, 25000.00, December

    December, Sales, 21000.00, January

    January,Marketing, 21322.00, February

     

    Don't think I'm grumpy or anything, but people will spend more time on your questions if you spend more time on your questions.

Viewing 3 posts - 1 through 2 (of 2 total)

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