Take the 2-minute tour ×

I am trying to insert into a table all data but change just the date column

So far I have something like


What I want to do is set one of the columns to be a constant value (like todays date instead of what is selected out)

Does anyone know of an easy way of doing that

share|improve this question
Is your question related to linq somehow? Why is there the linq-to-sql tag? –  ewernli Feb 16 '10 at 10:01
I have removed the linq-to-sql tag, as it has nothing to do with the question or possible answers. –  Otherside Feb 16 '10 at 10:37
add comment

5 Answers

up vote 4 down vote accepted
INSERT INTO MyTable (col1, col2, col3) (SELECT col1, col2, 'constant' FROM MyTable...)
share|improve this answer
add comment

Yes, you can do it like so:

INSERT INTO MyTable (SELECT MyTable.Id, MyTable.xxx, CONSTANT_VALUE FROM MyTable ...)
share|improve this answer
add comment

I would simply do the ffg

   Select col1, col2,....., THE_CONSTANT_VALUE, SOME_OTHER_VALUE from MyTable
share|improve this answer
add comment

You can do this if you specify the columns you are inserting into, something like this:

INSERT INTO MyTable (Col1, Col2, DateVal, StaticValue) (SELECT Col1, Col2, getdate() As DateVal, 'test' As StaticValue FROM MyTable2)

This would get Col1 and Col2 from MyTable2 but use the getdate() function to get the current date for the DateVal column, and every row inserted would have 'test' for the StaticValue column.

Does this help?

share|improve this answer
add comment

To update all the date field of every row in MyTable to the current date do:

UPDATE MyTable SET thedatecolumn = GETDATE()

If you want to insert from Table1 into Table2 where they have the same structure do:

INSERT INTO Table2 (column1, column2, column3, fixedcolumn) (SELECT column1, column2, 'textvalue' AS staticcolumn, GETDATE() AS functioncolumn FROM Table1)
share|improve this answer
add comment

Your Answer


