• masoudk1990 (5/6/2013)


    GilaMonster (5/6/2013)


    INSERT INTO TableName (ID,Value)

    SELECT coalesce(MAX(ID),0) + 1, 'something' FROM TableName;

    Thank you, hence this statement is not allowed:

    INSERT INTO TableName (Value1,value2)

    values(

    select value1 from table1,

    select value2 from table2

    )

    Instead you must join table1 and table2.

    Much appreciated

    Join them, maybe, depends what you're doing. You can't mix the INSERT ... VALUES form of the insert statement and the INSERT ... SELECT form. It's either insert with a values clause and a list of values or insert with a select statement.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass