SQL Server 2012 sequence
Just get rid of the subselect in the VALUES section, like this:
insert into Job_Update_Log(log_id,update_reason,jobid) values (next value for Job_Log_Update_SEQ,'grammer fixing',39);
Reference: http://msdn.microsoft.com/en-us/library/hh272694%28v=vs.103%29.aspx
Your insert syntax appears to be wrong. You are attempting to use a SELECT
statement inside of the VALUES
section of your query. If you want to use SELECT
then you will use:
insert into Job_Update_Log(log_id,update_reason,jobid) select next value for Job_Log_Update_SEQ,'grammer fixing',39;
I changed the syntax from INSERT INTO VALUES
to INSERT INTO ... SELECT
. I used this because you are selecting the next value of the sequence.
However, if you want to use the INSERT INTO.. VALUES
, you will have to remove the SELECT
from the query:
insert into Job_Update_Log(log_id,update_reason,jobid) values(next value for Job_Log_Update_SEQ,'grammer fixing',39);
Both of these will INSERT
the record into the table.
Try this one:
–With a table
create sequence idsequencestart with 1 increment by 3
create table Products_ext(id int,Name varchar(50));INSERT dbo.Products_ext (Id, Name)VALUES (NEXT VALUE FOR dbo.idsequence, ‘ProductItem’);select * from Products_ext;/* If you run the above statement two types, you will get the following:-1 ProductItem4 ProductItem*/drop table Products_ext;drop sequence idsequence;------------------------------