Hi,
I think the problem is here
SET @Autogenerate_Id = (SELECT TOP 1 Autogenerate_ID FROM Document_Management DM WHERE ID = (SELECT MAX(ID) FROM Document_Management WHERE Document_Type = @Document_Type))
IF @Autogenerate_Id IS NULL
BEGIN
SET @Autogenerate_Id = 'A0000'
END
The variable
@Autogenerate_Id
is always coming as
NULL
for that particular
@Document_Type
. check the value of
Autogenerate_ID
value in table
Document_Management
, and try check for non null values of this column. Then it may work.
Hope it helps.