You are viewing limited content. For full access, please sign in.

Question

Question

Execute Stored Procedure when Form Field is changed

asked on September 30, 2015

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

0 0

Replies

replied on October 8, 2015 Show version history

Hi Nate,  sorry about the long delay in responding.    I think I see a couple of problems with your stored procedure. 

'IF @notused is NOT NULL' is always going to be true because the value is blank.

So change that to IF @notused != '' and you will have better luck.

 

Also  '@notused varchar(50) output' doesn't seem right because the 'notused' is supposed to be input and not output.  Your picture in lookup configuration shows 'notused' as input so perhaps you fixed that part  already before you uploaded the picture. 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.