Select Into and Defaulting date field

faron used Ask the Experts™
I am running the following sql statement and would like to be able to default the date the statement was ran into all applicable records inserted on that date.

declare @date varchar(10)
set @date=convert(varchar, GETDATE(), 110)
INSERT Usage_HEAT (Tracker, Status)
SELECT LoginID, Status
FROM Tracker
WHERE Status %256>0

I have creted a variable to set the date but cannot come up with a good way to insert this into every record that is created during this insert.  The date would be written into the date_used column in the table in which the records are inserted.  In the future I will be tracking time as well as date, hence I wanted all records inserted when the statement is ran to have the same date and time.  I do not want the time to be different between inserted records.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
The easiest way to do this is to set the default for the date_used column to GetDate()

The other way is to add it every time you insert a row, as in
INSERT Usage_HEAT (Tracker, Status, date_used)
SELECT LoginID, Status, GetDate()
FROM Tracker
WHERE Status %256>0




I thought I tried this, but I guess I did not.  Anyway, you provided me the answer in a very timely fashion.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial