Insert statement to increase 1 new line for each document

  • Hello comunity

    I need to solve this problem about my TSQL Script :

    INSERT INTO [FOC04122007].[dbo].[owli]

    ([owlistamp]

    ,[dclistamp]

    ,[oldesc]

    , [owstamp])

    (select left(newid(),23),dcli.dclistamp,dcli.oldesc,(select distinct ow.owstamp from ow, owli , dc where owli.owstamp=ow.owstamp

    and ow.docnome=dc.docnome and ow.docnome like 'B11%') from dcli (nolock), dc (nolock) where dcli.dcstamp=dc.dcstamp and dcli.dclistamp='Adm08040969785,441068750')

    if i run only "select distinct ow.owstamp from ow, owli , dc where owli.owstamp=ow.owstamp

    and ow.docnome=dc.docnome and ow.docnome like 'B11%' ",

    i have 290 documents and i want to increase for each one , just on single line that i obtain by :

    (select left(newid(),23),dcli.dclistamp,dcli.oldesc from dcli (nolock), dc (nolock) where dcli.dcstamp=dc.dcstamp and dc.docnome like 'B11%' and dcli.dclistamp='Adm08040969785,441068750')

    note : dcli.dclistamp, identify the line of document B11% that i want to insert, because this doument have more than one line, but each one have a different dclistamp.

    How can do that , because i have the error because subquery return more than one row. I don´t know if it´s possible to do that with this kind of command.

    Many thanks

    Luis Santos

  • Hello comunity

    nobody have an ideia ?

    thanks

    Luis Santos

  • Instead of using the sub-query as part of the select list, make it a derived table, join against it, and you'll get a row for each value in that table.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

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

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