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 );
5
  • Where do you read your data from? Commented Feb 13, 2013 at 15:51
  • possible duplicate: stackoverflow.com/questions/452859/… Commented Feb 13, 2013 at 15:51
  • Do you want to change the current values or actually create new rows? Commented Feb 13, 2013 at 15:53
  • i have data from excel which i need to insert into table, actually insert new rows. Commented Feb 13, 2013 at 15:55
  • if the data's small enough, you can use the clipboard Commented Feb 13, 2013 at 16:17

3 Answers 3

1

Look into inserting with a SELECT:

INSERT INTO TABLE_NAMES (col1, col2, changingCol, col4)
SELECT
    ConstantValue1,
    ConstantValue2,
    MyChangingValue,
    ConstantValue4
FROM
   ...
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

-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';

3 Comments

I would like to insert SET_VALUE by keeping other row values being the same ------ I think he wants an update
On one of his comments, he says "i have data from excel which i need to insert into table, actually insert new rows". So he wants to insert them.
so he is having dynamic requirements :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.