I am looking to achieve similar results to this post but I cannot get my SQL statement to function properly. Per Robert's instruction, I am creating a IF clause in my SQL Statement, but for whatever reason it is triggering when the form loads AND when the field notused is changed. Below is my sql statement and screenshots from my form. Any help is much appreciated!
USE [LFForms]
GO
/****** Object: StoredProcedure [dbo].[sp_increment] Script Date: 9/30/2015 9:15:06 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_increment]
(
@notused varchar(50) output
)
AS
BEGIN
Declare @myvalue int
select @myvalue= [RequestNumber] from dbo.RequestNumber where name = 'access'
IF @notused is NOT NULL
BEGIN
update dbo.RequestNumber set [RequestNumber] = @myvalue + 1 where name = 'access'
Declare @myTable table
(
[RequestNumber] nvarchar(50)
)
INSERT INTO @myTable ([RequestNumber]) values (@myvalue)
select top 1 * from @mytable
RETURN @myvalue
END
ELSE BEGIN
RETURN @notused
END
END
Cheers!
Nate