I tried inserting values into a table that I created but while inserting into them through select statement I am getting an error message the code which I tried for insert is
create table dbo.watermarktable
(tablename varchar(255),
watermarkvalue datetime,
);
insert into dbo.watermarktable(tablename,watermarkvalue)
("reference_value", select max(created_date) from dbo.reference_value_genc);
but the values were not taken and thrown an error message and the error message is
Incorrect syntax near 'reference_value'.
Msg 102, Level 15, State 1, Line 7
Incorrect syntax near ')'.
Completion time: 2021-10-28T14:29:43.2357252 01:00
CodePudding user response:
You can either use VALUES
or SELECT
with INSERT INTO
. So Change your insert like this
insert into dbo.watermarktable(tablename,watermarkvalue)
SELECT 'reference_value', max(created_date) from dbo.reference_value_genc;
CodePudding user response:
Your syntax is a bit off, change it to this:
INSERT INTO dbo.watermarktable (tablename,watermarkvalue)
SELECT 'reference_value', max(created_date)
FROM dbo.reference_value_genc;