DECLARE @BusinessUnit AS Table( [id] varchar(10),sn int );
begin
INSERT INTO @BusinessUnit([id])
SELECT name
FROM test
WHERE course = 'Mca';
select * from @BusinessUnit;
end
how i assign auto increment value in sn field when the records are inserted in it. I Need the following type of output:
id 'Deepak' sn 1 and id 'Rohan' sn 2 like that
Modify your table variable to use IDENTITY property for sn column:
DECLARE @BusinessUnit AS Table( [id] varchar(10), sn int IDENTITY (1,1) );
The rest of your code should stay the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With