RE: force sql server to handle a subquery as correlated

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

From: Jan Schoenrock (Schoenrock_at_discussions.microsoft.com)
Date: 07/16/04


Date: Fri, 16 Jul 2004 02:27:02 -0700

Hello Nitin,

thanks for your help. Your suggstion might be helpful if there is no other who can insert data to the table a the same time, when running the loop.

Thanks again and best greetings

Jan

"Nitin Rana" wrote:

> 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: newbie: jsp / ms sql - nested queries problem
    ... > I'm writing html in a while loop in a jsp page. ... Statement can only have one active ResultSet at a time. ... You will need to set the server configuration to use ...
    (comp.lang.java.databases)
  • force sql server to handle a subquery as correlated
    ... My only suggestion is store the initial highest value in ... a variable and just keep on incrementing the variable ... you do need to do it in a loop. ... >I want to insert a resultset of a select statement into ...
    (microsoft.public.sqlserver.programming)
  • Select Distinct
    ... I am trying to create a resultset from an Access DB. ... Distinct statement to get unique results. ... loop, but it doesnt. ... I then get a SQL error. ...
    (comp.lang.java.databases)
  • Re: How to accessing columns of a query-result by index
    ... I want to access the columns of my resultset by index. ... > dreaming of something like this: ... > for i in 1..rec_data%colcount loop ... you may even want to consider dynamically generating an anonymous PL/SQL ...
    (comp.databases.oracle.server)