force sql server to handle a subquery as correlated

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Nitin Rana (Nitin_at_discussions.microsoft.com)
Date: 07/16/04


Date: Thu, 15 Jul 2004 18:26:40 -0700

My only suggestion is store the initial highest value in
a variable and just keep on incrementing the variable
value instead of running MAX(PKID) on each insert. But,
you do need to do it in a loop. I don't see any shortcut.

>-----Original Message-----
>Hi,
>
>I have the following question. Does anybody have an
idea ?
>
>I want to insert a resultset of a select statement into
a table wich has a non automated primary key.
>So for each record I have in my resultset I need to
generate a new PK by using a subquery:
>
>Insert into I(PKID, PKHist, IA,IB,IC)
>Select
>(Select MAX(PKID)+1 From I)
>1,
>XA,
>XB,
>YC
>>From X,Y
>
>So insert and select has to be handled together step by
step.
>select the first, insert the first, select the second,
insert the second.
>
>If there is a possibility to force such an behavior it
can be very smart.
>
>My only solution is to run such an insert by using loops
or cursors.
>
>I'll be very appreciate to receive some ideas ...
>
>thanks in advance
>
>Jan
>
>
>
>.
>



Relevant Pages

  • Re: Inputbox - exit routine
    ... Don't use a loop, use a hidden textbox on the form to store the number of times the OK button is clicked, by incrementing by one each time, and aborting if the value stored exceeds the limit. ...
    (microsoft.public.access.modulesdaovba)
  • Re: loops
    ... Ahmad Alkandri wrote: ... incrementing 0.001 ... ... and store the output values in a vector? ... If you are required to use a 'for' loop, ...
    (comp.soft-sys.matlab)
  • Re: compiler optimizing wrong?
    ... After each full declarator: ... compiler is free to move the loop below the store to ... that moving the loop to a position below the store to buffer_ready is ...
    (comp.lang.c)
  • Re: Comment on trim string function please
    ... Call strlenonce before the loop and ... store the result in a variable, and use that variable to control ... existing zero, which is harmless. ... going back and inspecting the moved characters a second time? ...
    (comp.lang.c)
  • Re: Increment for or do while loop by 0.001 (not 1)
    ... So a For/Next loop like this is not really adding 0.1 each time, ... If Fold <= Fnew Then 'If previous value of function is less ... xmax = X 'Store value of X for max value of F ...
    (microsoft.public.excel.programming)