Hi experts,
I am trying automatically increment the alpha numeric field (say for productid
in product
table).
But I am getting an error (see below). Could somebody please look into this error or any other approach to achieve this task?
My table details:
create table tblProduct
(
id varchar(15)
)
create procedure spInsertInProduct
AS
Begin
DECLARE @PId VARCHAR(15)
DECLARE @NId INT
DECLARE @COUNTER INT
SET @PId = 'PRD00'
SET @COUNTER = 0
--This give u max numeric id from the alphanumeric id
SELECT @NId = cast(substring(id, 3, len(id)) as int) FROM tblProduct group by left(id, 2) order by id
--here u increse the vlaue to numeric id by 1
SET @NId = @NId + 1
--GENERATE ACTUAL APHANUMERIC ID HERE
SET @PId = @PId + cast(@NId AS VARCHAR)
INSERT INTO tblProduct(id)values (@PId)
END
I am gettin the following error:
Msg 8120, Level 16, State 1, Procedure spInsertInProduct, Line 10 Column 'tblProduct.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. Msg 8120, Level 16, State 1, Procedure spInsertInProduct, Line 10 Column 'tblProduct.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.**