0

I would like to import an excel sheet to SQL using the import wizard and add an additional column to the table which has the current date.

For example:

In Excel, I have the following: Col1, Col2, Col3, Col4

In the SQL Table I would like: Col1, Col2, Col3, Col4 and an additional Col with the current date.

The table has all 5 columns with the 5th column a datetime datatype. I will delete the rows in the destination table before importing.

Please help.

2

2 Answers 2

2

Add a default value of GETDATE() to your table:

ALTER TABLE [dbo].[yourTable] 
      ADD CONSTRAINT [DF_yourDate]  DEFAULT (GETDATE()) FOR [yourDate]

Then just exclude yourDate column from inserts.

Sign up to request clarification or add additional context in comments.

Comments

2

When using Import Wizard you have the option of writing a query to specify the data transfer. This is adding the current datetime to a load from Sheet1.

    SELECT *,NOW() AS LoadDt FROM `Sheet1$`

LoadDt was placed first in data mapping, so in editing the SQL in that tab just moved that column to the end.

1 Comment

Using NOW() instead of GETDATE()for Excel SQL is the main thing.

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.