Question : Insert Data from a table and also add a date/time the data was added in a column called DateRcv

I have a query that is performing correctly.  However, I would like to modify it so It will add the date and time into a column I just added into the table.  The column I added was called "DateRcv".  I am wanting to track this data because I get this data at different times each month and would like to have the date when I get the data each month.

After I added the new column to table "billrunstatustable" I get the following error which is because I haven't told it what to update in the column.

Msg 213, Level 16, State 1, Line 3
Insert Error: Column name or number of supplied values does not match table definition.

So in summary:
I have one table that is being amended with this query.  It contains InvoicesRecdDate and DateRcv.  The first is supplied from the query the second is a date/time that the query is ran.
Code Snippet:
1:
2:
3:
4:
5:
If (Select Max(InvoiceDate) from bill.dbo.Invoices) > (Select Max(InvoicesRecdDate) from [Billing Automation Processes].dbo.billrunstatustable)
Begin
Insert Into [Billing Automation Processes].dbo.billrunstatustable
Select Max(InvoiceDate) from bill.dbo.Invoices
End

Answer : Insert Data from a table and also add a date/time the data was added in a column called DateRcv

I am assuming you are talking about DateRcv column.
You would the actual date time like this:
  getdate()

So, if  DateRcv needs to get updated when you run that insert query, your insert would be like this:

Insert Into [Billing Automation Processes].dbo.billrunstatustable (InvoicesRecdDate , DateRcv)
Select Max(InvoiceDate), getdate() from bill.dbo.Invoices

Let me know, if this does  not work for you.
Random Solutions  
 
programming4us programming4us