Hi
I want to increment primary key field value and insert into table, for that I am using a temp table and getting the incremented value and passing into the output parameter. This works fine, but With out using a temp a table how do I pass this incremented value into a variable and use this variable to insert into a table?
CREATE procedure test_proc
@table_name nvarchar(255),
@fld_name nvarchar(255),
@param_output nvarchar(255) output
as
declare @sql nvarchar(4000)
set @sql = 'insert into temp(id) select max('+@fld_name+')+1 from '+@table_name
Execute (@sql)
select @param_output =id from temp
set @sql = null
set @sql='insert into ' +@table_name+'('+@fld_name+')
values('+@param_output+')'
Execute(@sql)
delete temp
return @param_output
GO
I want to increment primary key field value and insert into table, for that I am using a temp table and getting the incremented value and passing into the output parameter. This works fine, but With out using a temp a table how do I pass this incremented value into a variable and use this variable to insert into a table?
CREATE procedure test_proc
@table_name nvarchar(255),
@fld_name nvarchar(255),
@param_output nvarchar(255) output
as
declare @sql nvarchar(4000)
set @sql = 'insert into temp(id) select max('+@fld_name+')+1 from '+@table_name
Execute (@sql)
select @param_output =id from temp
set @sql = null
set @sql='insert into ' +@table_name+'('+@fld_name+')
values('+@param_output+')'
Execute(@sql)
delete temp
return @param_output
GO