0

I am trying to insert GETDATE() value into a column with data type datetime2. But I am getting following error. I am using Azure SQL database.

This error is specific to getdate() function that i uses. I have see similar question with same error message but that scenario was complete different.

CREATE TABLE [dbo].[test] 
(
    [procedureName] NVARCHAR(900) COLLATE Latin1_General_100_CI_AS_KS_WS NULL, 
    [configCreated] DATETIME2(7) NOT NULL, 
    [configModified] DATETIME2(7) NOT NULL
)

Any idea why I am getting this error? I tried in my local SQL Server database, it worked but not in my office. I tried best from my end.

Insert into dbo.ETLLoadConfig('abc',getdate(), getdate()) -- it fails in azure sql DB

even tried this also: with a as(select cast(getdate() as datetime2) as date1) Insert into dbo.ETLLoadConfig('abc',(select date1 from a), (select date1 from a))

insert values statement can contain only constant literal values or variable references

Shankar Panda
  • 736
  • 3
  • 11
  • 27
  • 1
    It's great that you posted the DDL for the table, however you forgot to post the insert statement that failed.... – Zohar Peled Oct 25 '18 at 05:06
  • Also, if you want to save your self a lot of time in the future - 99 times out of 100, the easiest way to solve problems you encounter for the first time is just to google the error message. The first result of googling the error message you posted was the duplicate I've linked to. – Zohar Peled Oct 25 '18 at 05:09
  • I googled it. Do you think if that had answered i would have posted here. I see a strange behaviour with specific to getdate(). It works in my local sql server but not in azure sql db. – Shankar Panda Oct 25 '18 at 05:12
  • I wouldn't know, since you didn't write anything about it in the question. You should have wrote that you did try to search for the problem. What happened when you tried `insert...select` instead of `insert....values`? – Zohar Peled Oct 25 '18 at 05:14

0 Answers0