Insert Problem

  • hi,

    Can you please help me in this issue?

    create table #check

    (

    cno int ,

    sal int default(200)

    )

    --------

    insert into #check

    values (1, default)

    above query is working but below query is not working.

    insert into #check

    select 1, default

    why So?

    My Question : Is it not possible to insert default value by select?

    Cheers!

    Sandy.

    --

  • it's like with select: avoid implicit column references. if order of columns in your table changes, inserts may fail and it can be hard to track.

    this query works and it inserts default value to sal field:

    insert into #check (cno)

    select 2

    ...and your only reply is slàinte mhath

  • Hey Piotr Rodak,

    Thanks A Lot.

    Cheers!

    🙂

    Sandy.

    --

  • Hi Sandy,

    Piotr is right with the solution of removing the default from the select. The select statement should execute on its own when its result is used to put into another table. "select 1, default" is not a statement that is syntactically valid. Once you have got a statement that returns the expected result, you can use it in an insert statement, and can remap the columns.

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • Thanks Andras,

    For your quick reply,

    Cheers!

    Sandy.

    --

  • insert into has to be from exsiting table.

    get any existing table, select 2 fields and hardcode it.

    Insert into #check

    select 1 Column1, default Column1 from tbl1

Viewing 6 posts - 1 through 5 (of 5 total)

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