In the following sp, it builds row id's which are steps increment of 1.
upto 10 it is good, after 10 instead of 11, it is again showing 10.
here is my scritp within SP. which i use:Cast is the one it is causing issue.
CREATE TABLE #Steps(Step varchar(20) null)
DECLARE @i Int, @Max Int
SET @i = 1
IF @Edit = 0
INSERT INTO #Steps VALUES(null)
IF EXISTS(SELECT 1 FROM dbo.Tab_WorkflowActivity WHERE ModuleRecordID = @ModId And ModuleName = @ModuleName)
BEGIN
INSERT INTO #Steps SELECT DISTINCT Step FROM dbo.Tab_WorkflowActivity WHERE ModuleRecordID = @ModId And ModuleName = @ModuleName;
SELECT @Max = CAST(MAx(Step) As Int) FROM #Steps;
INSERT INTO #Steps VALUES(@Max + 1);
END
ELSE
BEGIN
INSERT INTO #Steps VALUES('1');
END
SELECT * from #Steps
Here are the results, it shows 10 after 10 instead of 11.
Step
-----
NULL
1
2
3
4
5
6
7
8
9
10
10 it should be 11.
Can you please tell me what am i doing wrong.
Thanks a lot for the helpful info.