1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Selecting a sequence NEXTVAL for multiple rows

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 31, 2024 às 08:23.

  1. Stack

    Stack Membro Participativo

    I am building a SQL Server job to pull data from SQL Server into an Oracle database through a linked server. The table I need to populate has a sequence for the name ID, which is my primary key. I'm having trouble figuring out a way to do this simply, without some lengthy code. Here's what I have so far for the SELECT portion (some actual names obfuscated):

    SELECT (SELECT NEXTVAL FROM OPENQUERY(MYSERVER,
    'SELECT ORCL.NAME_SEQNO.NEXTVAL FROM DUAL')),
    psn.BirthDate, psn.FirstName,
    psn.MiddleName, psn.LastName, c.REGION_CODE
    FROM Person psn
    LEFT JOIN MYSERVER..ORCL.COUNTRY c ON c.COUNTRY_CODE = psn.Country


    MYSERVER is the linked Oracle server, ORCL is obviously the schema. Person is a local table on the SQL Server database where the query is being executed.

    When I run this query, I get the same exact value for all records for the NEXTVAL. What I need is for it to generate a new value for each returned record.

    I found this similar question, with its answers, but am unsure how to apply it to my case (if even possible): Query several NEXTVAL from sequence in one statement

    Continue reading...

Compartilhe esta Página