--first variable
declare @code varchar(50);
set @code=1345688867567576;
--second variable
declare @namedb varchar(50);
set @namedb='test';
--let's you add to the identity(ID) field
SET IDENTITY_INSERT dbo.nameAndroid ON
--declaring variable to hold the next id number
declare @id int;
set @id=@@IDENTITY +1;
--clause to check if the table has the matching barcode
if not exists (select * from dbo.nameAndroid where barcode = @code)
INSERT INTO dbo.nameAndroid (id, name, barcode, [floor], Column1,Column2,Row1,Row2,Shelf,Stock,OnOrder)
VALUES ( @id,@namedb, @code, 'Value3', 'Value4','Value5','Value6','Value7','Value8',123,600);
SET IDENTITY_INSERT dbo.nameAndroid OFF;
OR (if the id column is of type int)
declare @code varchar(50);
set @code='123211';
declare @namedb varchar(50);
set @namedb='test';
declare @floordb varchar(50);
set @floordb='test';
declare @Column1db varchar(50);
set @Column1db='test';
declare @Column2db varchar(50);
set @Column2db='test';
declare @Row1db varchar(50);
set @Row1db='test';
declare @Row2db varchar(50);
set @Row2db='test';
declare @Shelfdb varchar(50);
set @Shelfdb='test';
declare @OnOrderdb decimal(18,2);
set @OnOrderdb=10010;
declare @Stockdb decimal(18,2);
set @Stockdb=1010101;
declare @id int;
set @id=((select max(id) from dbo.nameAndroid )+1);
if not exists (select * from dbo.nameAndroid where barcode = @code)
begin
SET IDENTITY_INSERT dbo.nameAndroid ON;
INSERT INTO dbo.nameAndroid (id, name, barcode, [floor], Column1,Column2,Row1,Row2,Shelf,Stock,OnOrder)
VALUES (@id, @namedb, @code, @floordb, @Column1db,@Column2db,@Row1db,@Row2db,@Shelfdb,@OnOrderdb,@Stockdb);
SET IDENTITY_INSERT dbo.nameAndroid OFF;
end