1

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 );
Mad-D
  • 4,479
  • 18
  • 52
  • 93

3 Answers3

1

Look into inserting with a SELECT:

INSERT INTO TABLE_NAMES (col1, col2, changingCol, col4)
SELECT
    ConstantValue1,
    ConstantValue2,
    MyChangingValue,
    ConstantValue4
FROM
   ...
zimdanen
  • 5,508
  • 7
  • 44
  • 89
1

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
Aleksandr Fedorenko
  • 16,594
  • 6
  • 37
  • 44
-1

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';
Community
  • 1
  • 1
Sandip Bantawa
  • 2,822
  • 4
  • 31
  • 47