Mad-D
Mad-D

Reputation: 4669

SQL Insert statement for multiple values

I am little confused whether we can accomplish inserting multiple rows / multiple values for few same values. To make it less complicated my table should look as shown below. Right now i have data in excel.

enter image description here

I would like to insert SET_VALUE by keeping other row values being the same. The only other option i can think of is inserting multiple times :(

INSERT INTO TABLE_NAME
  VALUES ( null, 100, 'miscellaneous', 'book', CURRENT_TIMESTAMP );

Upvotes: 1

Views: 2057

Answers (3)

Oleksandr Fedorenko
Oleksandr Fedorenko

Reputation: 16894

You can use OPENROWSET command. More examples to show some of the flexibility with the OPENROWSET command

let's assume that an ID IDENTITY

INSERT TABLE_NAME(SET_ID, SET_NAME, SET_VALUE, LOGIN_TIME)
SELECT 100, 'miscellaneous', SET_VALUE, CURRENT_TIMESTAMP 
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
                'Excel 8.0;Database = C:\OPENROWSET_Examples.xls;', 
                'SELECT SET_VALUE FROM [INSERT_Example$]') 
GO

Upvotes: 1

Sandip Bantawa
Sandip Bantawa

Reputation: 2880

Try this link

QUOTE

UPDATE a
  SET a.CalculatedColumn = b.[Calculated Column]
  FROM Table1 AS a
  INNER JOIN Table2 AS b
  ON a.CommonField = b.[Common Field]
  WHERE a.BatchNo = '110';

Upvotes: -1

zimdanen
zimdanen

Reputation: 5626

Look into inserting with a SELECT:

INSERT INTO TABLE_NAMES (col1, col2, changingCol, col4)
SELECT
    ConstantValue1,
    ConstantValue2,
    MyChangingValue,
    ConstantValue4
FROM
   ...

Upvotes: 1

Related Questions